Hamming numbers: Difference between revisions

→‎Explicit multiples reinserting: explicitly show the empirical orders of growth for the leftover queue
(→‎{{header|Pascal}}: correct "slow" reference and add enough BigInt to print the millionth value...)
(→‎Explicit multiples reinserting: explicitly show the empirical orders of growth for the leftover queue)
Line 5,252:
<lang Haskell>hamm n = drop n $ iterate (\(_,(a:t))-> (a,union t [2*a,3*a,5*a])) (0,[1])</lang>
{{out}}
<lang Haskell>*Main> maptake fst20 $ takemap 20fst $ hamm 1
[1,2,3,4,5,6,8,9,10,12,15,16,18,20,24,25,27,30,32,36]
 
*Main> maptake fst2 $ takemap 2fst $ hamm 1691
[2125764000,2147483648]
 
*Main> mapM_ print $ take 10 $ hamm 1
(1,[2,3,5])
(2,[3,4,5,6,10])
Line 5,270:
(12,[15,16,18,20,24,25,27,30,36,40,45,50,60])
 
*Main> map (length.snd.head.hamm) [2000,4000,8000,16000]
[402,638,1007,1596]</lang>
 
Runs too slowly to reach 1,000,000, with empirical orders of growth above ''~''&zwj;&thinsp;&zwj;(''n''&zwj;&thinsp;&zwj;<sup>1.7</sup>&zwj;&thinsp;&zwj;) and worsening. Last two lines show the internal buffer's length for several sample ''n''&zwj;&thinsp;&zwj;s.
> map (logBase 2) $ zipWith (/) =<< tail $ [402,638,1007,1596]
[0.67,0.66,0.66]</lang>
Runs too slowly to reach 1,000,000, with empirical orders of growth above ''~''&zwj;&thinsp;&zwj;(''n''&zwj;&thinsp;&zwj;<sup>1.7</sup>&zwj;&thinsp;&zwj;) and worsening. Last two lines show the internal buffer's length for several sample ''n''&zwj;&thinsp;&zwj;s, and its [http://en.wikipedia.org/wiki/Analysis_of_algorithms#Empirical_orders_of_growth ''empirical'' orders of growth] which strongly support the <math>O(n^{2/3})</math> claim.
 
===Enumeration by a chain of folded merges===
751

edits