Hamming numbers: Difference between revisions

m
Line 6,684:
=={{header|Lambdatalk}}==
 
<h2>===1) recursive version</h2>===
 
<syntaxhighlight lang="scheme">
 
{def hamming
{def hamming.loop
Line 6,720 ⟶ 6,721:
{hamming 1691}
-> 2125764000 // < 200ms
 
Currently limited to javascript's integers and by stackoverflow on some computers.
 
</syntaxhighlight>
 
<h2>===2) iterative version</h2>===
 
<h3>2.1) compute</h3>
Build a table of 2^i•3^j•5^k from i,j,k = 0 to n and sort it.
 
<h3>===2.1) compute</h3>===
 
<syntaxhighlight lang="scheme">
 
{def ham
{lambda {:n}
Line 6,750 ⟶ 6,756:
-> 2125764000 // on my macbook pro
 
</syntaxhighlight>
<h3>2.2) display</h3>
 
<h3>===2.2) display</h3>===
Display a hamming number as 2^a•3^b•5^c
 
Display a hamming number as 2^a•3^b•5^<sup>a</sup>•3<sup>b</sup>•5<sup>c</sup>
 
<syntaxhighlight lang="scheme">
 
{def factor
Line 6,811 ⟶ 6,821:
18: 32 = 2^5•3^0•5^0
19: 36 = 2^2•3^2•5^0
 
</syntaxhighlight>
 
See http://lambdaway.free.fr/lambdawalks/?view=hamming_numbers3 for a better display as 2<sup>a</sup>•3<sup>b</sup>•5<sup>c</sup>.
 
=={{header|Liberty BASIC}}==
99

edits