map infimum => [ min ] map-reduce
parent
25f8eeab6f
commit
e88812b76a
|
@ -1,6 +1,6 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: fry namespaces sequences math accessors kernel arrays
|
USING: fry namespaces sequences math math.order accessors kernel arrays
|
||||||
combinators compiler.utilities assocs
|
combinators compiler.utilities assocs
|
||||||
stack-checker.backend
|
stack-checker.backend
|
||||||
stack-checker.branches
|
stack-checker.branches
|
||||||
|
@ -54,7 +54,7 @@ M: #branch normalize*
|
||||||
] map unzip swap
|
] map unzip swap
|
||||||
] change-children swap
|
] change-children swap
|
||||||
[ remaining-introductions set ]
|
[ remaining-introductions set ]
|
||||||
[ [ length ] map infimum introduction-stack [ swap head ] change ]
|
[ [ length ] [ min ] map-reduce introduction-stack [ swap head ] change ]
|
||||||
bi ;
|
bi ;
|
||||||
|
|
||||||
: eliminate-phi-introductions ( introductions seq terminated -- seq' )
|
: eliminate-phi-introductions ( introductions seq terminated -- seq' )
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
! Copyright (c) 2008 Aaron Schaefer.
|
! Copyright (c) 2008 Aaron Schaefer.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: kernel math math.functions math.ranges project-euler.common sequences ;
|
USING: kernel math math.functions math.ranges math.order
|
||||||
|
project-euler.common sequences ;
|
||||||
IN: project-euler.044
|
IN: project-euler.044
|
||||||
|
|
||||||
! http://projecteuler.net/index.php?section=problems&id=44
|
! http://projecteuler.net/index.php?section=problems&id=44
|
||||||
|
@ -37,7 +38,7 @@ PRIVATE>
|
||||||
|
|
||||||
: euler044 ( -- answer )
|
: euler044 ( -- answer )
|
||||||
2500 [1,b] [ nth-pentagonal ] map dup cartesian-product
|
2500 [1,b] [ nth-pentagonal ] map dup cartesian-product
|
||||||
[ first2 sum-and-diff? ] filter [ first2 - abs ] map infimum ;
|
[ first2 sum-and-diff? ] filter [ first2 - abs ] [ min ] map-reduce ;
|
||||||
|
|
||||||
! [ euler044 ] 10 ave-time
|
! [ euler044 ] 10 ave-time
|
||||||
! 4996 ms ave run time - 87.46 SD (10 trials)
|
! 4996 ms ave run time - 87.46 SD (10 trials)
|
||||||
|
|
Loading…
Reference in New Issue