Super-d numbers: Difference between revisions

Content added Content deleted
(→‎{{header|Lua}}: added Lua solution)
Line 860: Line 860:
17546133 32613656 93568867 107225764 109255734 113315082 121251742 175461330 180917907 182557181
17546133 32613656 93568867 107225764 109255734 113315082 121251742 175461330 180917907 182557181
Run time 392181 ms</pre>
Run time 392181 ms</pre>

=={{header|Lua}}==
==={{header|Lua - using doubles}}===
Lua's default numeric type is IEEE-754 doubles, which are insufficient beyond d=5, but for reference:
<lang lua>for d = 2, 5 do
local n, found = 0, {}
while #found < 10 do
local dnd = string.format("%15.f", d * n ^ d)
local dds = string.rep(d, d)
if string.find(dnd, dds) then found[#found+1] = n end
n = n + 1
end
print("super-" .. d .. ": " .. table.concat(found,", "))
end</lang>
{{out}}
<pre>super-2: 19, 31, 69, 81, 105, 106, 107, 119, 127, 131
super-3: 261, 462, 471, 481, 558, 753, 1036, 1046, 1471, 1645
super-4: 1168, 4972, 7423, 7752, 8431, 10267, 11317, 11487, 11549, 11680
super-5: 4602, 5517, 7539, 9469, 12955, 14555, 20137, 20379, 26629, 35689</pre>
==={{header|Lua - using lbc}}===
Using the lbc library to provide support for arbitrary-precision integers, which are sufficient for both task and extra-credit:
<lang lua>bc = require("bc")
for i = 2, 9 do
local d, n, found = bc.new(i), bc.new(0), {}
while #found < 10 do
local dnd = (d * n ^ d):tostring()
local dds = string.rep(d:tostring(), d:tonumber())
if string.find(dnd, dds) then found[#found+1] = n:tostring() end
n = n + 1
end
print("super-" .. d:tostring() .. ": " .. table.concat(found,", "))
end</lang>
{{out}}
<pre>super-2: 19, 31, 69, 81, 105, 106, 107, 119, 127, 131
super-3: 261, 462, 471, 481, 558, 753, 1036, 1046, 1471, 1645
super-4: 1168, 4972, 7423, 7752, 8431, 10267, 11317, 11487, 11549, 11680
super-5: 4602, 5517, 7539, 12955, 14555, 20137, 20379, 26629, 32767, 35689
super-6: 27257, 272570, 302693, 323576, 364509, 502785, 513675, 537771, 676657, 678146
super-7: 140997, 490996, 1184321, 1259609, 1409970, 1783166, 1886654, 1977538, 2457756, 2714763
super-8: 185423, 641519, 1551728, 1854230, 6415190, 12043464, 12147605, 15517280, 16561735, 18542300
super-9: 17546133, 32613656, 93568867, 107225764, 109255734, 113315082, 121251742, 175461330, 180917907, 182557181</pre>


=={{header|Pascal}}==
=={{header|Pascal}}==