Hamming numbers: Difference between revisions
Content added Content deleted
Lpicouleau (talk | contribs) |
(Added XPL0 example.) |
||
Line 12,865: | Line 12,865: | ||
The last of these found in 16 milliseconds. |
The last of these found in 16 milliseconds. |
||
</pre> |
</pre> |
||
=={{header|XPL0}}== |
|||
<syntaxhighlight lang "XPL0">func Hamming(N); \Return 'true' if N is a Hamming number |
|||
int N; |
|||
[if N = 1 then return true; |
|||
if rem(N/2) = 0 then return Hamming(N/2); |
|||
if rem(N/3) = 0 then return Hamming(N/3); |
|||
if rem(N/5) = 0 then return Hamming(N/5); |
|||
return false; |
|||
]; |
|||
int N, C; |
|||
[N:= 1; C:= 0; |
|||
loop [if Hamming(N) then |
|||
[C:= C+1; |
|||
IntOut(0, N); ChOut(0, ^ ); |
|||
if C >= 20 then quit; |
|||
]; |
|||
N:= N+1; |
|||
]; |
|||
CrLf(0); |
|||
N:= 1<<31; \ 8-) |
|||
repeat N:= N-1 until Hamming(N); |
|||
IntOut(0, N); |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 2 3 4 5 6 8 9 10 12 15 16 18 20 24 25 27 30 32 36 |
|||
2125764000</pre> |
|||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |
||
Line 12,878: | Line 12,907: | ||
sub hamming(limit) |
sub hamming(limit) |
||
local x2, |
local x2, |
||
x3,x5,i,j,k,n |
|||
h(0) =1 |
h(0) =1 |