Smallest numbers: Difference between revisions
Content added Content deleted
Line 162: | Line 162: | ||
The integer precision of stedolan jq is insufficient for this task.<lang 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 |
# 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 power($b): . as $a | reduce range(0; $b) as $i (1; . * $a); |
||
Line 170: | Line 167: | ||
def smallest_k: |
def smallest_k: |
||
tostring as $n |
tostring as $n |
||
| first( |
| first( range(1; infinite) | select( power(.) | tostring | contains($n))) ; |
||
</lang> |
</lang> |
||
<lang jq> |
<lang jq> |