class String
def score
total = 0
# ascii 'a' is 97, 97-96 = 1
self.strip.downcase.each_byte{|c| total += (c - 96)}
total
end
end
words = []
File.open("/usr/share/dict/words", "r") do |file|
file.each_line {|line| words << line.strip}
end
ninetynine = words.find_all {|word| word.score == 99}
3 notes
Posted on Tuesday October 13th
-
robmandu liked this
-
johnryanpowell reblogged this from phoenyxblog and added:
I always love reading your code. I had thought about doing something similar. But it would have been 500 lines of code....
-
johnryanpowell liked this
-
phoenyxblog posted this