! 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
[ [ 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 ]
: 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>
! [ euler215 ] 100 ave-time
! 208 ms ave run time - 9.06 SD (100 trials)
-MAIN: euler215
+SOLUTION: euler215