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