User talk:Nigel Galloway: Difference between revisions

Line 23:
 
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==
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 [http://ruby-doc.org/core-2.0/String.html#method-i-chomp 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{|line| line.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. [[User:Markjreed|Markjreed]] ([[User talk:Markjreed|talk]]) 10:20, 15 May 2013 (UTC)
1,479

edits