Skip to content
Browse files

add project-euler.203

  • Loading branch information...
1 parent 2489ac5 commit 8ace93a75f9c62cc78b9569a6656724333589944 @glguy committed Nov 10, 2008
Showing with 14 additions and 0 deletions.
  1. +5 −0 extra/project-euler/203/203-tests.factor
  2. +9 −0 extra/project-euler/203/203.factor
View
5 extra/project-euler/203/203-tests.factor
@@ -0,0 +1,5 @@
+USING: project-euler.203 tools.test ;
+IN: project-euler.203.tests
+
+[ 105 ] [ 8 solve ] unit-test
+[ 34029210557338 ] [ 51 solve ] unit-test
View
9 extra/project-euler/203/203.factor
@@ -0,0 +1,9 @@
+USING: fry kernel math math.primes.factors sequences sets ;
+IN: project-euler.203
+
+: iterate ( n initial quot -- results ) swapd '[ @ dup ] replicate nip ; inline
+: (generate) ( seq -- seq ) [ 0 prefix ] [ 0 suffix ] bi [ + ] 2map ;
+: generate ( n -- seq ) 1- { 1 } [ (generate) ] iterate concat prune ;
+: squarefree ( n -- ? ) factors duplicates empty? ;
+: solve ( n -- n ) generate [ squarefree ] filter sum ;
+: euler203 ( -- n ) 51 solve ;

0 comments on commit 8ace93a

Please sign in to comment.
Something went wrong with that request. Please try again.