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