Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,27 @@
! rosetta/hailstone/length/length.factor
USING: assocs kernel io math math.ranges prettyprint
rosetta.hailstone sequences ;
IN: rosetta.hailstone.length
<PRIVATE
: f>0 ( object/f -- object/0 )
dup [ drop 0 ] unless ;
: max-value ( pair1 pair2 -- pair )
[ [ second ] bi@ > ] most ;
: main ( -- )
H{ } clone ! Maps sequence length => count.
1 100000 [a,b) [
hailstone length ! Find sequence length.
over [ f>0 1 + ] change-at ! Add 1 to count.
] each
! Find the length-count pair with the highest count.
>alist unclip-slice [ max-value ] reduce
first2 swap
"Among Hailstone sequences from 1 <= n < 100000," print
"there are " write pprint
" sequences of length " write pprint "." print ;
PRIVATE>
MAIN: main