! Copyright (c) 2009 Guillaume Nargeot.
! See http://factorcode.org/license.txt for BSD license.
-USING: fry io.encodings.ascii io.files locals kernel math
-math.order math.parser math.ranges sequences splitting
-project-euler.common ;
+USING: io.encodings.ascii io.files kernel math math.order
+math.parser project-euler.common sequences splitting ;
IN: project-euler.081
! http://projecteuler.net/index.php?section=problems&id=081
:: minimal-path-sum-to ( x y matrix -- n )
x y + zero? [ 0 ] [
x zero? [ 0 y 1 - matrix get-matrix
- ] [
+ ] [
y zero? [
x 1 - 0 matrix get-matrix
] [
3dup minimal-path-sum-to '[ _ + ] change-matrix ;
: (euler081) ( matrix -- n )
- dup first length [0,b) dup cartesian-product
- [ first2 pick update-minimal-path-sum ] each
+ dup first length <iota> dup
+ [ pick update-minimal-path-sum ] cartesian-each
last last ;
PRIVATE>