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 7 of 12 Topic 4022 of 4173
Post > Topic >>

Re: Euler problem #22

by Slava Pestov <slava@[EMAIL PROTECTED] > Apr 29, 2008 at 08:57 PM

On Apr 29, 4:30=A0pm, Jonah Thomas <jethom...@[EMAIL PROTECTED]
> wrote:
> Oh well. We don't mind useing RPN, or a data stack, or weak typing.

You don't have to give up RPN or the stack to solve this problem in a
concise way. Here is the Factor solution:

: alpha-value ( str -- n )
    >lower [ CHAR: a - 1+ ] sigma ;

: source-022 ( -- seq )
    "resource:extra/project-euler/022/names.txt"
    ascii file-contents [ quotable? ] filter "," split ;

: name-scores ( seq -- seq )
    [ 1+ swap alpha-value * ] map-index ;

: euler-022 ( -- answer )
    source-022 natural-sort name-scores sum ;

We have solutions to about 70 project euler problems so far, and most
of them are very short:

http://factorcode.org/responder/cgi/gitweb.cgi?p=3Dfactor.git;a=3Dtree;f=3De=
xtra/project-euler;h=3Dc5ba0c4ac8b33de81d0030cbd5abce2ac990e7fa;hb=3DHEAD
 




 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 22:20:54 CDT 2008.