40 lines
1 KiB
Text
40 lines
1 KiB
Text
global count
|
|
|
|
procedure main(A)
|
|
limit1 := \A[1] | 50
|
|
limit2 := \A[2] | 1000
|
|
showcounts(humbles(limit1, limit2))
|
|
end
|
|
|
|
procedure humbles(limit1,limit2)
|
|
scounts := table(0)
|
|
every (count := 0, n := genhumbles()\limit2, count +:= 1, x := *n) do {
|
|
if 0 < (limit1 -:= 1) then writes(" ",n)
|
|
else if 0 = limit1 then write(" ",n)
|
|
scounts[x] +:= 1
|
|
}
|
|
return scounts
|
|
end
|
|
|
|
procedure genhumbles()
|
|
suspend 1
|
|
p := [2,3,5,7]
|
|
l := [0,0,0,0]
|
|
ch := []
|
|
every n := seq() do {
|
|
suspend m := min(p[1],p[2],p[3],p[4])
|
|
put(ch, m)
|
|
if m = p[1] then p[1] := 2*ch[l[1] +:= 1]
|
|
if m = p[2] then p[2] := 3*ch[l[2] +:= 1]
|
|
if m = p[3] then p[3] := 5*ch[l[3] +:= 1]
|
|
if m = p[4] then p[4] := 7*ch[l[4] +:= 1]
|
|
}
|
|
end
|
|
|
|
procedure showcounts(counts)
|
|
write("\nOut of the first ",count," humble numbers:\n")
|
|
write(" length ",center("count",16))
|
|
write(" ",repl("-",5)," ",repl("-",16))
|
|
every p := !sort(counts) do
|
|
write(right(p[1],7)," ",right(p[2],16))
|
|
end
|