Tweak Project Euler solutions to use existing words

db4
Aaron Schaefer 2008-02-12 23:31:10 -05:00
parent 84901e6dbc
commit 24f5c9e40d
2 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,7 @@
! Copyright (c) 2007 Aaron Schaefer. ! Copyright (c) 2007 Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: ascii io.files kernel math project-euler.common sequences sorting splitting ; USING: ascii io.files kernel math project-euler.common sequences sequences.lib
sorting splitting ;
IN: project-euler.022 IN: project-euler.022
! http://projecteuler.net/index.php?section=problems&id=22 ! http://projecteuler.net/index.php?section=problems&id=22
@ -31,7 +32,7 @@ IN: project-euler.022
file-contents [ quotable? ] subset "," split ; file-contents [ quotable? ] subset "," split ;
: name-scores ( seq -- seq ) : name-scores ( seq -- seq )
dup length [ 1+ swap alpha-value * ] 2map ; [ 1+ swap alpha-value * ] map-index ;
PRIVATE> PRIVATE>

View File

@ -1,6 +1,7 @@
! Copyright (c) 2008 Aaron Schaefer. ! Copyright (c) 2008 Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: arrays combinators.lib kernel math math.primes math.primes.factors math.ranges namespaces sequences ; USING: arrays combinators.lib kernel math math.primes math.primes.factors
math.ranges namespaces sequences ;
IN: project-euler.047 IN: project-euler.047
! http://projecteuler.net/index.php?section=problems&id=47 ! http://projecteuler.net/index.php?section=problems&id=47
@ -54,8 +55,8 @@ PRIVATE>
! ALTERNATE SOLUTIONS ! ALTERNATE SOLUTIONS
! ------------------- ! -------------------
! Use a sieve to generate prime factor counts up to a limit, then look for a ! Use a sieve to generate prime factor counts up to an arbitrary limit, then
! repetition of the specified number of factors. ! look for a repetition of the specified number of factors.
<PRIVATE <PRIVATE
@ -84,12 +85,12 @@ SYMBOL: sieve
PRIVATE> PRIVATE>
: euler047a ( -- answer ) : euler047a ( -- answer )
4 1000000 consecutive-under ; 4 200000 consecutive-under ;
! [ euler047a ] 100 ave-time ! [ euler047a ] 100 ave-time
! 2589 ms run / 45 ms GC ave time - 100 trials ! 503 ms run / 5 ms GC ave time - 100 trials
! TODO: I don't like that you have to specify the upper bound, maybe try making ! TODO: I don't like that you have to specify the upper bound, maybe try making
! this lazy so it will also short-circuit when it finds the answer? ! this lazy so it could also short-circuit when it finds the answer?
MAIN: euler047a MAIN: euler047a