Humble numbers: Difference between revisions

→‎Fast and economical: improve space management
(→‎Fast and economical: improve space management)
Line 3,111:
def update:
.[0] as $h
| ([$h * 2, $h * 3, $h * 5, $h * 7] | map(select(tostring|length <= $digits))) as $next
| (.[1:]if + [$hnext *== 2[] +then $next) | sort;.[1:]
else (.[1:] + $next) | sort
end;
def trim: if length <= 1 then . elif .[0]==.[1] then .[1:]|trim else . end;
{ h: 1, queue: [2,3,5,71]}
| whilerecurse( select( .h|tostring|length)queue <!= $digits;[] )
.queue | .h = trim.queue[0]
| queue |= (update|trim) )
| .h = .queue[0]
| (.queueh |= update);
)
| .h;
 
def distribution(stream):
Line 3,149:
15: 7545
16: 9081</pre>
 
The queue in this case grows to a maximum length of about 18K.
 
=={{header|Julia}}==
2,489

edits