Super-d numbers: Difference between revisions
Content added Content deleted
m (Updated description and link for Fōrmulæ solution) |
|||
Line 806: | Line 806: | ||
Run time 268460 ms |
Run time 268460 ms |
||
</pre> |
</pre> |
||
=={{header|jq}}== |
|||
'''Works with gojq, the Go implementation of jq''' |
|||
The C implementation of jq does not have sufficiently accurate integer arithmetic to fulfill the task, |
|||
so the output shown below is based on a run of gojq. |
|||
<lang jq># To take advantage of gojq's arbitrary-precision integer arithmetic: |
|||
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in); |
|||
# Input is $d, the number of consecutive digits, 2 <= $d <= 9 |
|||
# $max is the number of superd numbers to be emitted. |
|||
def superd($number): |
|||
. as $d |
|||
| tostring as $s |
|||
| ($s * $d) as $target |
|||
| {count:0, j: 3 } |
|||
| while ( .count <= $number; |
|||
.emit = null |
|||
| if ((.j|power($d) * $d) | tostring) | index($target) |
|||
then .count += 1 |
|||
| .emit = .j |
|||
else . |
|||
end |
|||
| .j += 1 ) |
|||
| select(.emit).emit ; |
|||
# super-d for 2 <=d < 8 |
|||
range(2; 8) |
|||
| "First 10 super-\(.) numbers:", |
|||
superd(10)</lang> |
|||
{{out}} |
|||
<pre> |
|||
First 10 super-2 numbers: |
|||
19 |
|||
31 |
|||
69 |
|||
81 |
|||
105 |
|||
106 |
|||
107 |
|||
119 |
|||
127 |
|||
131 |
|||
First 10 super-3 numbers: |
|||
261 |
|||
462 |
|||
471 |
|||
481 |
|||
558 |
|||
753 |
|||
1036 |
|||
1046 |
|||
1471 |
|||
1645 |
|||
First 10 super-4 numbers: |
|||
1168 |
|||
4972 |
|||
7423 |
|||
7752 |
|||
8431 |
|||
10267 |
|||
11317 |
|||
11487 |
|||
11549 |
|||
11680 |
|||
First 10 super-5 numbers: |
|||
4602 |
|||
5517 |
|||
7539 |
|||
12955 |
|||
14555 |
|||
20137 |
|||
20379 |
|||
26629 |
|||
32767 |
|||
35689 |
|||
First 10 super-6 numbers: |
|||
27257 |
|||
272570 |
|||
302693 |
|||
323576 |
|||
364509 |
|||
502785 |
|||
513675 |
|||
537771 |
|||
676657 |
|||
678146 |
|||
First 10 super-7 numbers: |
|||
140997 |
|||
490996 |
|||
1184321 |
|||
1259609 |
|||
1409970 |
|||
1783166 |
|||
1886654 |
|||
1977538 |
|||
2457756 |
|||
2714763 |
|||
</pre> |
|||
=={{header|Julia}}== |
=={{header|Julia}}== |