Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Executable-library/Factor/executable-library-1.factor
Normal file
31
Task/Executable-library/Factor/executable-library-1.factor
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
! rosetta/hailstone/hailstone.factor
|
||||
USING: arrays io kernel math math.ranges prettyprint sequences vectors ;
|
||||
IN: rosetta.hailstone
|
||||
|
||||
: hailstone ( n -- seq )
|
||||
[ 1vector ] keep
|
||||
[ dup 1 number= ]
|
||||
[
|
||||
dup even? [ 2 / ] [ 3 * 1 + ] if
|
||||
2dup swap push
|
||||
] until
|
||||
drop ;
|
||||
|
||||
<PRIVATE
|
||||
: main ( -- )
|
||||
27 hailstone dup dup
|
||||
"The hailstone sequence from 27:" print
|
||||
" has length " write length .
|
||||
" starts with " write 4 head [ unparse ] map ", " join print
|
||||
" ends with " write 4 tail* [ unparse ] map ", " join print
|
||||
|
||||
! Maps n => { length n }, and reduces to longest Hailstone sequence.
|
||||
1 100000 [a,b)
|
||||
[ [ hailstone length ] keep 2array ]
|
||||
[ [ [ first ] bi@ > ] most ] map-reduce
|
||||
first2
|
||||
"The hailstone sequence from " write pprint
|
||||
" has length " write pprint "." print ;
|
||||
PRIVATE>
|
||||
|
||||
MAIN: main
|
||||
Loading…
Add table
Add a link
Reference in a new issue