Fix common Project Euler word alpha-num
parent
b15f88f0b8
commit
170d8d8c51
|
@ -1,7 +1,6 @@
|
|||
! Copyright (c) 2007 Aaron Schaefer.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: io.files kernel math math.parser namespaces sequences sorting splitting
|
||||
strings system vocabs ascii ;
|
||||
USING: ascii io.files kernel math project-euler.common sequences sorting splitting ;
|
||||
IN: project-euler.022
|
||||
|
||||
! http://projecteuler.net/index.php?section=problems&id=22
|
||||
|
@ -31,9 +30,6 @@ IN: project-euler.022
|
|||
"extra/project-euler/022/names.txt" resource-path
|
||||
file-contents [ quotable? ] subset "," split ;
|
||||
|
||||
: alpha-value ( str -- n )
|
||||
[ string>digits sum ] keep length 9 * - ;
|
||||
|
||||
: name-scores ( seq -- seq )
|
||||
dup length [ 1+ swap alpha-value * ] 2map ;
|
||||
|
||||
|
@ -43,9 +39,9 @@ PRIVATE>
|
|||
source-022 natural-sort name-scores sum ;
|
||||
|
||||
! [ euler022 ] 100 ave-time
|
||||
! 59 ms run / 1 ms GC ave time - 100 trials
|
||||
! 123 ms run / 4 ms GC ave time - 100 trials
|
||||
|
||||
! source-022 [ natural-sort name-scores sum ] curry 100 ave-time
|
||||
! 45 ms run / 1 ms GC ave time - 100 trials
|
||||
! 93 ms run / 2 ms GC ave time - 100 trials
|
||||
|
||||
MAIN: euler022
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
USING: arrays combinators.lib kernel math math.functions math.miller-rabin
|
||||
math.matrices math.parser math.primes.factors math.ranges namespaces
|
||||
sequences sorting ;
|
||||
sequences sorting unicode.case ;
|
||||
IN: project-euler.common
|
||||
|
||||
! A collection of words used by more than one Project Euler solution
|
||||
|
@ -8,6 +8,7 @@ IN: project-euler.common
|
|||
|
||||
! Problems using each public word
|
||||
! -------------------------------
|
||||
! alpha-value - #22, #42
|
||||
! cartesian-product - #4, #27, #29, #32, #33
|
||||
! collect-consecutive - #8, #11
|
||||
! log10 - #25, #134
|
||||
|
@ -52,6 +53,9 @@ IN: project-euler.common
|
|||
|
||||
PRIVATE>
|
||||
|
||||
: alpha-value ( str -- n )
|
||||
>lower [ CHAR: a - 1+ ] sigma ;
|
||||
|
||||
: cartesian-product ( seq1 seq2 -- seq1xseq2 )
|
||||
swap [ swap [ 2array ] map-with ] map-with concat ;
|
||||
|
||||
|
|
Loading…
Reference in New Issue