Created
September 4, 2010 17:48
-
-
Save canweriotnow/565350 to your computer and use it in GitHub Desktop.
Solution to Euler problem 22 in Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ruby script to solve Euler Problem 22 | |
# names.txt d/l'd from http://projecteuler.net/project/names.txt | |
nf = File.open("names.txt", 'r') | |
names = nf.gets.scan(/\w+/).sort | |
total = 0 | |
names.each_with_index do |n,i| | |
tmp = 0 | |
n.each_byte { |c| tmp += (c - 64) } | |
tmp *= (i + 1) | |
total += tmp | |
end | |
puts total |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment