Smallest numbers: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: changed a comment.) |
(Added Python implementation) |
||
Line 663: | Line 663: | ||
Same results, but nearly 30 times faster, finishing the 1,000,000 test in just 26.6s |
Same results, but nearly 30 times faster, finishing the 1,000,000 test in just 26.6s |
||
=={{header|Python}}== |
|||
Interactive script which takes the upper bound as input : |
|||
<lang Python> |
|||
#Aamrun, 4th October 2021 |
|||
import sys |
|||
if len(sys.argv)!=2: |
|||
print("Usage : python " + sys.argv[0] + " <whole number>") |
|||
exit() |
|||
numLimit = int(sys.argv[1]) |
|||
resultSet = {} |
|||
base = 1 |
|||
while len(resultSet)!=numLimit: |
|||
result = base**base |
|||
for i in range(0,numLimit): |
|||
if str(i) in str(result) and i not in resultSet: |
|||
resultSet[i] = base |
|||
base+=1 |
|||
[print(resultSet[i], end=' ') for i in sorted(resultSet)] |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
C:\My Projects\BGI>python rosetta9.py 51 |
|||
9 1 3 5 2 4 4 3 7 9 10 11 5 19 22 26 8 17 16 19 9 8 13 7 17 4 17 3 11 18 13 5 23 17 18 7 17 15 9 18 16 17 9 7 12 28 6 23 9 24 23 |
|||
</pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
<lang perl6>sub smallest ( $n ) { |
<lang perl6>sub smallest ( $n ) { |