19 lines
599 B
Text
19 lines
599 B
Text
var BN=Import("zklBigNum"); // only needed for large N
|
|
fcn hamming(N){
|
|
h:=List.createLong(N+1); (0).pump(N+1,h.write,Void); // fill list with stuff
|
|
h[0]=1;
|
|
#if 1 // regular (64 bit) ints
|
|
x2:=2; x3:=3; x5:=5; i:=j:=k:=0;
|
|
#else // big ints
|
|
x2:=BN(2); x3:=BN(3); x5:=BN(5); i:=j:=k:=0;
|
|
#endif
|
|
foreach n in ([1..N]){
|
|
z:=(x2<x3) and x2 or x3; z=(z<x5) and z or x5; h[n]=z;
|
|
if (h[n] == x2) { x2 = h[i+=1]*2 }
|
|
if (h[n] == x3) { x3 = h[j+=1]*3 }
|
|
if (h[n] == x5) { x5 = h[k+=1]*5 }
|
|
}
|
|
return(h[N-1])
|
|
}
|
|
[1..20].apply(hamming).println();
|
|
hamming(1691).println();
|