Add project-euler.148

db4
Eric Mertens 2008-04-19 23:41:26 -07:00
parent 6c70907354
commit fbe7fb58dd
1 changed files with 24 additions and 0 deletions
extra/project-euler/148

View File

@ -0,0 +1,24 @@
! Copyright (c) 2008 Eric Mertens
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math math.functions sequences sequences.lib ;
IN: project-euler.148
<PRIVATE
: sum-1toN ( n -- sum )
dup 1+ * 2/ ; inline
: >base7 ( x -- y )
[ dup 0 > ] [ 7 /mod ] [ ] unfold nip ;
: (use-digit) ( prev x index -- next )
[ [ 1+ * ] [ sum-1toN 7 sum-1toN ] bi ] dip ^ * + ;
PRIVATE>
: (euler148) ( x -- y )
>base7 0 [ (use-digit) ] reduce-index ;
: euler148 ( -- y )
10 9 ^ (euler148) ;