Paste: PE #73
Author: | elasticdog |
Mode: | factor |
Date: | Tue, 11 Nov 2008 03:26:11 |
Plain Text |
USING: kernel locals make math project-euler.common sequences ;
IN: project-euler.073
<PRIVATE
: (euler073) ( limit lo hi -- )
pick [ 2dup mediant denominator ] dip <= [
2dup mediant dup , tuck swap [ pick ] 2dip (euler073) (euler073)
] [ 3drop ] if ;
:: (euler073a) ( limit lo hi -- )
lo hi mediant denominator limit <= [
lo hi mediant dup ,
[ [ limit lo ] dip (euler073a) ]
[ [ limit ] dip hi (euler073a) ] bi
] when ;
PRIVATE>
: euler073 ( -- answer )
[ 10000 1/3 1/2 (euler073a) ] { } make length ;
Author: | elasticdog |
Mode: | factor |
Date: | Tue, 11 Nov 2008 03:27:28 |
Plain Text |
USING: math math.ratios ;
: mediant ( a/c b/d -- (a+b)/(c+d) )
2>fraction [ + ] 2bi@ / ;
Author: | elasticdog |
Mode: | factor |
Date: | Tue, 11 Nov 2008 03:45:34 |
Plain Text |
<PRIVATE
:: (euler073) ( limit lo hi -- )
[let | m [ lo hi mediant ] |
m denominator limit <= [
m ,
limit lo m (euler073)
limit m hi (euler073)
] when
] ;
PRIVATE>
: euler073 ( -- answer )
[ 10000 1/3 1/2 (euler073) ] { } make length ;
Author: | slava |
Mode: | factor |
Date: | Tue, 11 Nov 2008 03:49:11 |
Plain Text |
:: (euler073) ( limit lo hi -- )
lo hi mediant dup denominator limit <= [
[ , ]
[ [ limit lo ] dip (euler073) ]
[ [ limit ] dip hi (euler073) ]
tri
] when ;
New Annotation