Done puzzle 49
[project-euler.git] / euler22.rb
1 require 'logger'
2 $log = Logger.new(STDERR)
3 $log.level = Logger::WARN
4
5 def value_of_char(char)
6 char.ord - "A".ord + 1
7 end
8
9 def value_of_word(word)
10 word.scan(/./).map{|c| value_of_char c}.reduce(:+)
11 end
12
13 if __FILE__==$0
14 total = 0
15 $names = File.read('euler22-names.txt').strip.slice(1..-2).split('","').sort
16 $names.each_index do |i|
17 total += (i + 1) * value_of_word($names[i])
18 end
19
20 puts total
21 end
22
23 $log.close