Smallest numbers: Difference between revisions
Content added Content deleted
(Added Sidef) |
|||
Line 157: | Line 157: | ||
18 7 17 15 9 18 16 17 9 7 12 28 6 23 9 24 23 |
18 7 17 15 9 18 16 17 9 7 12 28 6 23 9 24 23 |
||
</pre> |
</pre> |
||
=={{header|jq}}== |
|||
'''Works with gojq, the Go implementation of jq''' |
|||
The integer precision of stedolan jq is insufficient for this task.<lang jq> |
|||
# Generate the positive integers |
|||
def positive_integers: 1 | recurse(.+1); |
|||
# if the input and $b are integers, then gojq will preserve precision |
|||
def power($b): . as $a | reduce range(0; $b) as $i (1; . * $a); |
|||
def smallest_k: |
|||
tostring as $n |
|||
| first( positive_integers | select( power(.) | tostring | contains($n))) ; |
|||
</lang> |
|||
<lang jq> |
|||
# Formatting |
|||
def lpad($len): tostring | ($len - length) as $l | (" " * $l)[:$l] + .; |
|||
def nwise($n): |
|||
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end; |
|||
n; |
|||
</lang>The task:<lang jq> |
|||
def task($n): |
|||
[range(0; $n) | smallest_k | lpad(3) ] |
|||
| nwise(10) |
|||
| join(" "); |
|||
task(51)</lang> |
|||
{{out}} |
|||
As for Factor, for example. |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |