! Copyright (c) 2008 Eric Mertens.
! See http://factorcode.org/license.txt for BSD license.
-USING: fry kernel math math.primes.factors sequences sets project-euler.common ;
+USING: fry kernel math math.primes.factors math.vectors sequences sets
+project-euler.common ;
IN: project-euler.203
! http://projecteuler.net/index.php?section=problems&id=203
swapd '[ @ dup ] replicate nip ; inline
: (generate) ( seq -- seq )
- [ 0 prefix ] [ 0 suffix ] bi [ + ] 2map ;
+ [ 0 prefix ] [ 0 suffix ] bi v+ ;
: generate ( n -- seq )
1 - { 1 } [ (generate) ] iterate combine ;
USING: accessors arrays byte-arrays fry hints kernel lists make math
math.functions math.matrices math.order math.parser math.primes.factors
math.primes.lists math.primes.miller-rabin math.ranges math.ratios
- namespaces parser prettyprint quotations sequences sorting strings
- unicode.case vocabs vocabs.parser words ;
+ math.vectors namespaces parser prettyprint quotations sequences sorting
+ strings unicode.case vocabs vocabs.parser words ;
FROM: sequences => change-nth ;
IN: project-euler.common
: max-path ( triangle -- n )
dup length 1 > [
- 2 cut* first2 max-children [ + ] 2map suffix max-path
+ 2 cut* first2 max-children v+ suffix max-path
] [
first first
] if ;