Skip to content

Instantly share code, notes, and snippets.

@canweriotnow
Created September 4, 2010 17:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canweriotnow/565350 to your computer and use it in GitHub Desktop.
Save canweriotnow/565350 to your computer and use it in GitHub Desktop.
Solution to Euler problem 22 in Ruby
# 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