]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/project-euler/215/215.factor
factor: trim using lists
[factor.git] / extra / project-euler / 215 / 215.factor
index 82d6a31c6691c744a3ccaa83f6c844d5cd088f13..5ae262ff9ad1cfa555d696e60a842c17be2ee865 100644 (file)
@@ -1,6 +1,6 @@
 ! Copyright (c) 2008 Eric Mertens.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors kernel locals math ;
+USING: accessors kernel math project-euler.common ;
 IN: project-euler.215
 
 ! http://projecteuler.net/index.php?section=problems&id=215
@@ -33,8 +33,8 @@ TUPLE: end { ways integer } ;
 
 C: <block> block
 C: <end> end
-: <failure> 0 <end> ; inline
-: <success> 1 <end> ; inline
+: <failure> ( -- end ) 0 <end> ; inline
+: <success> ( -- end ) 1 <end> ; inline
 
 : failure? ( t -- ? ) ways>> 0 = ; inline
 
@@ -42,8 +42,8 @@ C: <end> end
     [ [ two>> ] [ three>> ] bi ] 2dip bi* ; inline
 
 GENERIC: merge ( t t -- t )
-GENERIC# block-merge 1 ( t t -- t )
-GENERIC# end-merge 1 ( t t -- t )
+GENERIC#: block-merge 1 ( t t -- t )
+GENERIC#: end-merge 1 ( t t -- t )
 M: block merge block-merge ;
 M: end   merge end-merge ;
 M: block block-merge [ [ two>>   ] bi@ merge ]
@@ -72,14 +72,14 @@ M: end h2 dup failure? [ <failure> <block> ] unless ;
 
 : first-row ( n -- t )
     [ <failure> <success> <failure> ] dip
-    1- [| a b c | b c <block> a b ] times 2drop ;
+    1 - [| a b c | b c <block> a b ] times 2drop ;
 
 GENERIC: total ( t -- n )
 M: block total [ total ] dup choice + ;
 M: end   total ways>> ;
 
 : solve ( width height -- ways )
-    [ first-row ] dip 1- [ next-row ] times total ;
+    [ first-row ] dip 1 - [ next-row ] times total ;
 
 PRIVATE>
 
@@ -89,4 +89,4 @@ PRIVATE>
 ! [ euler215 ] 100 ave-time
 ! 208 ms ave run time - 9.06 SD (100 trials)
 
-MAIN: euler215
+SOLUTION: euler215