]> gitweb.factorcode.org Git - factor.git/blobdiff - extra/project-euler/215/215.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / extra / project-euler / 215 / 215.factor
index fc09b375159af11147280ee114a9030d4d85bfd8..1006b7a4cf25de71ce0ca2d96a8af19b4fbd32e1 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 locals math project-euler.common ;
 IN: project-euler.215
 
 ! http://projecteuler.net/index.php?section=problems&id=215
@@ -9,7 +9,7 @@ IN: project-euler.215
 ! -----------
 
 ! Consider the problem of building a wall out of 2x1 and 3x1 bricks
-! (horizontalvertical dimensions) such that, for extra strength, the gaps
+! (horizontal x vertical dimensions) such that, for extra strength, the gaps
 ! between horizontally-adjacent bricks never line up in consecutive layers,
 ! i.e. never form a "running crack".
 
@@ -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
 
@@ -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