On Apr 27, 3:51 pm, William James <w_a_x_...@[EMAIL PROTECTED]
> wrote:
> On Apr 27, 7:29 am, m...@[EMAIL PROTECTED]
(Marcel Hendrix) wrote:
> > The total of all the name scores in the file names.txt is
18,049,839,040
>
> I arrive at a much smaller number.
According to Project Euler, my result is correct.
>
>
>
> > 0.005 seconds elapsed. ok
Since this problem takes so little time for the computer to solve,
the amount of time needed to write the program is infinitely more
im****tant. Making the program as fast as possible is simply a
waste of human effort.
A shorter program:
$names = IO.read("names.txt").scan(/[A-Z]+/).sort
sum = 0
$names.each_with_index do |name,i|
sum += i.succ * name.split('').
inject(0){|n,c| n + c[0] - ?A + 1}
end
p sum


|