Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Forth > Re: Euler probl...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 12 Topic 4022 of 4173
Post > Topic >>

Re: Euler problem #22

by William James <w_a_x_man@[EMAIL PROTECTED] > Apr 29, 2008 at 08:31 AM

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
 




 12 Posts in Topic:
Euler problem #22
mhx@[EMAIL PROTECTED] (M  2008-04-27 14:29:26 
Re: Euler problem #22
William James <w_a_x_m  2008-04-27 13:51:04 
Re: Euler problem #22
William James <w_a_x_m  2008-04-29 08:31:00 
Re: Euler problem #22
Andrew Haley <andrew29  2008-04-29 12:34:13 
Re: Euler problem #22
mhx@[EMAIL PROTECTED] (M  2008-04-29 20:44:53 
Re: Euler problem #22
Bruce McFarling <agila  2008-04-29 11:35:03 
Re: Euler problem #22
Slava Pestov <slava@[E  2008-04-29 20:57:36 
Re: Euler problem #22
mhx@[EMAIL PROTECTED] (M  2008-04-30 09:34:59 
Re: Euler problem #22
Zev Weiss <i_dance_on_  2008-04-30 08:05:58 
Re: Euler problem #22
mhx@[EMAIL PROTECTED] (M  2008-04-30 10:59:09 
Re: Euler problem #22
Albert van der Horst <  2008-04-30 08:19:44 
Re: Euler problem #22
Jonah Thomas <jethomas  2008-04-29 17:30:15 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 17:07:51 CDT 2008.