! Copyright (c) 2008 Aaron Schaefer.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math math.parser sequences strings ;
+USING: kernel math math.parser sequences project-euler.common ;
IN: project-euler.040
! http://projecteuler.net/index.php?section=problems&id=40
: (concat-upto) ( n limit str -- str )
2dup length > [
- pick number>string over push-all rot 1+ -rot (concat-upto)
+ pick number>string append! [ 1 + ] 2dip (concat-upto)
] [
2nip
] if ;
SBUF" " clone 1 -rot (concat-upto) ;
: nth-integer ( n str -- m )
- [ 1- ] dip nth 1string 10 string>integer ;
+ [ 1 - ] dip nth digit> ;
PRIVATE>
[ swap nth-integer ] with map product ;
! [ euler040 ] 100 ave-time
-! 1002 ms run / 43 ms GC ave time - 100 trials
+! 444 ms ave run time - 23.64 SD (100 trials)
-MAIN: euler040
+SOLUTION: euler040