User talk:Nigel Galloway: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎Special_Ordered_Sets_of_Type_N: Candidate for deletion?)
No edit summary
Line 14: Line 14:
:<math>a_1 + b^2</math>
:<math>a_1 + b^2</math>
This lets you avoid having to fiddle around with uploading pictures. (Mediawiki's configured to convert simple math to UNICODE for rendering, and complex stuff gets run through (La)TeX.) It's pretty awesome to use this for things like [[Continued fractions]]… –[[User:Dkf|Donal Fellows]] 21:28, 27 February 2012 (UTC)
This lets you avoid having to fiddle around with uploading pictures. (Mediawiki's configured to convert simple math to UNICODE for rendering, and complex stuff gets run through (La)TeX.) It's pretty awesome to use this for things like [[Continued fractions]]… –[[User:Dkf|Donal Fellows]] 21:28, 27 February 2012 (UTC)

==Huge Ruby example==
Hi, You've just added a simply huge example in Ruby to a page. Could you modify it to read the dict from a file or, if you insist on keeping it as it is, could you move it to a sub-page on its own. Thanks. --[[User:Paddy3118|Paddy3118]] 15:30, 10 September 2012 (UTC)

==Huge addition to Ledrug's page==
Hi, unless Ledrug specifically asked for the data, it seems impolite to dump so much on his page and I would urge you to remove it as it can only cause offense. --[[User:Paddy3118|Paddy3118]] 13:01, 27 October 2012 (UTC)
: That's Nigel Galloway being Nigel Galloway. The content was from [[Talk:Kaprekar numbers]], which he somehow felt very strongly the urge to remove, probably because I said something not very flattering to him there. I undid that change because deleting 30k+ talk without even a word of explanation was basically vandalism, so he decided that those should go on my talk page instead (and of course it was removed from the original place again). Come to think of it, I kinda suspect this paragraph won't survive very long, either. --[[User:Ledrug|Ledrug]] 13:47, 27 October 2012 (UTC)

Hi Nigel, it's the 'net. People are wrong/right and rarely polite all the time, but that doesn't mean that one can't try and carve out a good community project and get something done through the noise. How about taking a deep breath and just letting it go? You could move on to your next RC contribution and get something else done. There is rarely any material victory ''or'' loss to the people having the dispute but it can leave people too focused on the argument to the detriment of the 'feel' and reputation of the community. --[[User:Paddy3118|Paddy3118]] 16:19, 27 October 2012 (UTC)


==Minor tweaks to Ruby Semordnilap==
==Minor tweaks to Ruby Semordnilap==
Line 45: Line 36:
==[[Talk:Special_Ordered_Sets_of_Type_N#Candidate for deletion?]]==
==[[Talk:Special_Ordered_Sets_of_Type_N#Candidate for deletion?]]==
Hi, just to make you aware .... --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 04:38, 7 July 2013 (UTC)
Hi, just to make you aware .... --[[User:Paddy3118|Paddy3118]] ([[User talk:Paddy3118|talk]]) 04:38, 7 July 2013 (UTC)

==Thinning==
==={{header|Ruby}}===
First I define a function zs which given a point and its eight neighbours returns 1 if the point may be culled, 0 otherwise. g indicates if this is step 1 or step 2 in the task description. zs may be changed to remembers the step independently if the reader does not wish to explore the algorithm.

Substituting for g==0 in the code
<lang>
(ng[1][2] + ng[0][1] + ng[1+g][g]) (ng[g][1+g] + ng[2][1] + ng[1][0])
</lang>
gives (P4 P2 P8) (P2 P8 P6) in the nomenclature used in the task description.

Similarly substituting g==1 gives (P4 P2 P6) (P4 P6 P8).

This line must be correct; each of the 4 directions is ignored in one of the triples, each of [1][2], [0][1], [2][1], and [1][0] is ignored as required by the algorithm!!!!!!!--[[User:Nigel Galloway|Nigel Galloway]] ([[User talk:Nigel Galloway|talk]]) 09:43, 21 October 2013 (UTC)
<lang ruby>
# Thinning RC
# Nigel_Galloway: October 18th., 2013.
require 'csv'
s2 = CSV.read("smallRC.csv", converters: :numeric)
@r = 1
s1 = Array.new(s2.length){Array.new(s2[0].length,0)}

def zs(ng,g)
return 0 if ng[1][1] == 0 or (ng[1][2] + ng[0][1] + ng[1+g][g]) == 3 or (ng[g][1+g] + ng[2][1] + ng[1][0]) == 3
t = -1; ng.each{|n| n.each{|g| t+=g}}; return 0 unless (2 <= t and t <= 6)
t=-1;[ng[0][1],ng[0][2],ng[1][2],ng[2][2],ng[2][1],ng[2][0],ng[1][0],ng[0][0],ng[0][1]].each{|n| t+=(t==0 or t==2)? n : 1-n}
return 0 unless t==1 or t==2
@r=1
end
</lang>

To reproduce the output described in the task description it is necessary to call zs first with g=1 (though either way produces a valid thinned output): See [[Zhang-Suen thinning algorithm/bigRC.csv]] for the input file contents
<lang ruby>
s2.each{|row| row.each{|col| print(col==1? "#": " ")}; print("\n")}
while @r == 1
@r = 0
(1...s2.length-1).each{|n| (1...s2[0].length-1).each{|g| s1[n][g] = s2[n][g] - zs(s2[n-1..n+1].collect{|n| n[g-1..g+1]},1)}}
(1...s2.length-1).each{|n| (1...s2[0].length-1).each{|g| s2[n][g] = s1[n][g] - zs(s1[n-1..n+1].collect{|n| n[g-1..g+1]},0)}}
end
s2.each{|row| row.each{|col| print(col==1? "#": " ")}; print("\n")}
</lang>
{{out}}
<pre>
################# #############
################## ################
################### ##################
######## ####### ###################
###### ####### ####### ######
###### ####### #######
################# #######
################ #######
################# #######
###### ####### #######
###### ####### #######
###### ####### ####### ######
######## ####### ###################
######## ####### ###### ################## ######
######## ####### ###### ################ ######
######## ####### ###### ############# ######
# ########## #######
## # #### #
# # ##
# # #
# # #
# # #
############ #
# # #
# # #
# # #
# # #
# ##
# ############
### ###
</pre>

Revision as of 15:20, 29 October 2013

In re Execute Ramsey Mathprog; what were you trying to achieve with that? What language were you writing in? –Donal Fellows 13:16, 5 January 2012 (UTC)

Solution pages

Hey there. I see you've been creating separate pages for the long output from Mathprog programs. That's good, but I want to suggest creating pages with titles like Task name/Language name to make sure people using every language can get a separate page if they need it. A page like KnapU sol should go at Knapsack problem/Unbounded/Mathprog instead. An added benefit of doing that is that it automatically adds a link back to the task at the top of the output page. Thanks for your solutions so far. It's nice to get new languages here. --Mwn3d 14:20, 10 January 2012 (UTC)

Signatures

To sign your posts, use --~~~~. You've signed a few using [[User:Dkf|Nigel Galloway]], which actually links over to Donal Fellow's user page. --Michael Mol 22:49, 13 January 2012 (UTC)

Math on RC

Did you know that we can use pieces of text like “<math>a_1 + b^2</math>” (with TeX/LaTeX formatted code inside) to create stuff that renders as:

This lets you avoid having to fiddle around with uploading pictures. (Mediawiki's configured to convert simple math to UNICODE for rendering, and complex stuff gets run through (La)TeX.) It's pretty awesome to use this for things like Continued fractions… –Donal Fellows 21:28, 27 February 2012 (UTC)

Minor tweaks to Ruby Semordnilap

I found your approach to the solution refreshingly different from the others on the page. Very nice. I have a few notes on the Ruby specifics that you may find useful:

  • Ruby has String#chomp built-in, so there's no need to reimplement it with a manual tr.
  • Blocks of the form { |obj| obj.method } can be shortened to parameters of the form &:method.
  • String#== has the same semantics as String#eql? and seems to be preferred by the community in idiomatic Ruby.
  • Instead of initializing an array to empty and then pushing onto it conditionally inside a loop, you can construct the new array as a piece by using select instead of each.

Applying those to your code, you get this:

   DICT=File.readlines("unixdict.txt").collect(&:chomp)
   i = 0
   res = DICT.collect(&:reverse).sort.select { |z|
     i+=1 while z > DICT[i] and i < DICT.length-1
     z == DICT[i] and z < z.reverse
   }

Hope you find the above useful or at least interesting. --Markjreed (talk) 10:20, 15 May 2013 (UTC)

Thanks for the interest. The manual tr was put in by Paddy3118 so I take no credit for it and I am more than happy to make the change. Spoon! then changed it to use a set in immitation of the Python. I wasn't happy about that!, walking sorted files seemed good to me. C has since implemented that to perfection. The each seems more natural to me, in the real world I would probably want to write these pairs to a file or something, but for the purpose of this example why not?--Nigel Galloway (talk) 12:09, 17 May 2013 (UTC)

Talk:Special_Ordered_Sets_of_Type_N#Candidate for deletion?

Hi, just to make you aware .... --Paddy3118 (talk) 04:38, 7 July 2013 (UTC)

Thinning

Ruby

First I define a function zs which given a point and its eight neighbours returns 1 if the point may be culled, 0 otherwise. g indicates if this is step 1 or step 2 in the task description. zs may be changed to remembers the step independently if the reader does not wish to explore the algorithm.

Substituting for g==0 in the code <lang> (ng[1][2] + ng[0][1] + ng[1+g][g]) (ng[g][1+g] + ng[2][1] + ng[1][0]) </lang> gives (P4 P2 P8) (P2 P8 P6) in the nomenclature used in the task description.

Similarly substituting g==1 gives (P4 P2 P6) (P4 P6 P8).

This line must be correct; each of the 4 directions is ignored in one of the triples, each of [1][2], [0][1], [2][1], and [1][0] is ignored as required by the algorithm!!!!!!!--Nigel Galloway (talk) 09:43, 21 October 2013 (UTC)

<lang ruby>

  1. Thinning RC
  2. Nigel_Galloway: October 18th., 2013.

require 'csv' s2 = CSV.read("smallRC.csv", converters: :numeric) @r = 1 s1 = Array.new(s2.length){Array.new(s2[0].length,0)}

def zs(ng,g)

 return 0 if ng[1][1] == 0 or (ng[1][2] + ng[0][1] + ng[1+g][g]) == 3 or (ng[g][1+g] + ng[2][1] + ng[1][0]) == 3
 t = -1; ng.each{|n| n.each{|g| t+=g}}; return 0 unless (2 <= t and t <= 6)
 t=-1;[ng[0][1],ng[0][2],ng[1][2],ng[2][2],ng[2][1],ng[2][0],ng[1][0],ng[0][0],ng[0][1]].each{|n| t+=(t==0 or t==2)? n : 1-n}
 return 0 unless t==1 or t==2
 @r=1

end </lang>

To reproduce the output described in the task description it is necessary to call zs first with g=1 (though either way produces a valid thinned output): See Zhang-Suen thinning algorithm/bigRC.csv for the input file contents <lang ruby> s2.each{|row| row.each{|col| print(col==1? "#": " ")}; print("\n")} while @r == 1

 @r = 0
 (1...s2.length-1).each{|n| (1...s2[0].length-1).each{|g| s1[n][g] = s2[n][g] - zs(s2[n-1..n+1].collect{|n| n[g-1..g+1]},1)}}
 (1...s2.length-1).each{|n| (1...s2[0].length-1).each{|g| s2[n][g] = s1[n][g] - zs(s1[n-1..n+1].collect{|n| n[g-1..g+1]},0)}}

end s2.each{|row| row.each{|col| print(col==1? "#": " ")}; print("\n")} </lang>

Output:
 #################                   #############         
 ##################               ################         
 ###################            ##################         
 ########     #######          ###################         
   ######     #######         #######       ######         
   ######     #######        #######                       
   #################         #######                       
   ################          #######                       
   #################         #######                       
   ######     #######        #######                       
   ######     #######        #######                       
   ######     #######         #######       ######         
 ########     #######          ###################         
 ########     ####### ######    ################## ######  
 ########     ####### ######      ################ ######  
 ########     ####### ######         ############# ######  
                                                           
                                                           
                                                           
    # ##########                       #######             
     ##        #                   ####       #            
     #          #                 ##                       
     #          #                #
     #          #                #                         
     #          #                #                         
     ############               #                          
     #          #               #                          
     #          #                #                         
     #          #                #                         
     #          #                #                         
     #                            ##                       
     #                             ############            
                       ###                          ###