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