Super-d numbers: Difference between revisions
Added FreeBASIC
m (→{{header|R}}) |
(Added FreeBASIC) |
||
(11 intermediate revisions by 6 users not shown) | |||
Line 26:
{{trans|D}}
<
L(ii) 2..7
Line 41:
print("\n")
L.break
j++</
{{out}}
Line 63:
140997 490996 1184321 1259609 1409970 1783166 1886654 1977538 2457756 2714763
</pre>
=={{header|Amazing Hopper}}==
{{trans|C}}
<p>Debido a que los tipos básicos de Hopper son INT, LONG y DOUBLE, no es posible cumplir con la tarea en los términos específicos de ésta; sin embargo, sí es posible encontrar números "SUPER-D" teniendo en cuenta las limitaciones del coma-flotante, y calculando un poco más.</p>
<p>El coma flotante usado por Hopper garantiza que los primeros 16 dígitos de la parte entera son significativos (correctos), dejando a los restantes dígitos a la imaginación del computador. Esto me permite encontrar números SUPER-D cuyo "target" se encuentre dentro de los primeros 16 dígitos.</p>
<p>Si bien es cierto que la tarea requiere del uso de tipos BIG-INT, asumo que, habiendo encontrado algunos números, ésta está cumplida.</p>
<p>Para SUPER-9, es imposible encontrar números bajo las limitaciones de Hopper.</p>
<p>El resultado fue intervenido para resumir la aparición de los mensajes de error.</p>
<p>
Nota 1: los números grandes fueron comprobados (al menos, los primeros 16 dígitos), en la siguiente página:
</p>
<p>https://calculado.net/calculadora-de-numeros-grandes</p>
<p>Nota 2: por supuesto, algunos de los números desde SUPER-6 en adelante pueden ser incorrectos, porque se debe considerar el número completo como resultado real y correcto. Sin embargo, dudo que estén completamente erróneos, porque de lo contrario tendríamos un problema con el tipo DOUBLE y la confianza en los primeros 16 dígitos.</p><p>Dejo esta nota (2) aquí para su discusión ;) </p>
<syntaxhighlight lang="c">
#include <basico.h>
algoritmo
decimales '0'
d=2
ir a sub mientras ( #(d<=8), encontrar súperd )
terminar
subrutinas
sub( encontrar súperd )
imprimir("First 10 super-",d," numbers:\n")
count=0, j = 3.0, target=""
#(target = replicate( chr( 48 + d), d ))
iterar mientras ' #(count < 10) '
cuando( #(occurs(target, string( (j^d) * d ))) ){
si ( #( find(target,string( (j^d) * d ))<=16-d+1 ) )
++count, #((j^d) * d ),";"#(int(j)),"\n", imprimir
sino
imprimir("Error by limited floating-point\n")
fin si
}
++j
reiterar
saltar
++d
retornar
</syntaxhighlight>
{{out}}
<pre>
$ hopper3 basica/superd.bas
First 10 super-2 numbers:
722;19
1922;31
9522;69
13122;81
22050;105
22472;106
22898;107
28322;119
32258;127
34322;131
First 10 super-3 numbers:
53338743;261
295833384;462
313461333;471
333853923;481
521223336;558
1280873331;753
3335803968;1036
3433336008;1046
9549030333;1471
13354233375;1645
First 10 super-4 numbers:
7444428488704;1168
2444468646298624;4972
12144449506652164;7423
14444916891992064;7752
20210466987444484;8431
44446159394566080;10267
65612298930444480;11317
69644444001866240;11487
71160258444475208;11549
74444284887040000;11680
First 10 super-5 numbers:
10320555555665840128;4602
25555531873653735424;5517
121769555550158815232;7539
1824555552575530729472;12955
3266111849055555420160;14555
16555559203438988361728;20137
17574555554247478345728;20379
66949030555551289835520;26629
289495555554740940046336;35689
295053655555780915494912;35825
First 10 super-6 numbers:
Error by limited floating-point (x7)
6886666667204071324753900265799680;323576
110225436666664177977616958115282944;513675
Error by limited floating-point (x2)
583566666663286739658021176443142144;678146
Error by limited floating-point (x11)
75170784666666152681821170513110630400;1523993
Error by limited floating-point (x3)
116749666666722233392107835976969093120;1640026
Error by limited floating-point (x3)
176076108666666759379592167193103564800;1756271
Error by limited floating-point (x2)
250899451666666024467063188536426496000;1863051
Error by limited floating-point
266666617561594553577481823130432307200;1882072
436901766666679373685701878627629531136;2043488
Error by limited floating-point (x4)
666666906920386920350237344359883210752;2192601
First 10 super-7 numbers:
Error by limited floating-point (x12)
177777775600462518614052285223994784063074336768;4258476
Error by limited floating-point (x4)
993035700777777764170988126348947335750126403584;5444788
Error by limited floating-point (x16)
46713777777797451604889330385832487876519153106944;9438581
Error by limited floating-point (x3)
127977777771329971103305441414911647224808683339776;10900183
Error by limited floating-point (x2)
185944035777777783325705920417758962467398899204096;11497728
Error by limited floating-point (x6)
401493021777777721293822883896686959196909141491712;12834193
Error by limited floating-point (x2)
620807777777080769345318482826386545204255464095744;13658671
Error by limited floating-point (x3)
851802177777771784337179797881318978935678922915840;14290071
Error by limited floating-point (x6)
1907267777777317249638349869607811168558639577300992;16034108
1917295477777774148415418596878943250105383734214656;16046124
First 10 super-8 numbers:
Error by limited floating-point (x8)
4277888888883959171581268707647711439890179731079492513300480;29242698
Error by limited floating-point (x6)
98986718888888801286918789785886389895645834536018691101818880;43307276
117888888882653975719110834321860851108606954628126584961236992;44263715
Error by limited floating-point (x5)
627806888888889341739385231069597287624565300411183649261617152;54555936
Error by limited floating-point (x7)
14888888883417818657923930639384765827471804545865401634268381184;81044125
Error by limited floating-point (x20)
540888888884903246645687533027412939667041397478034734067117719552;126984952
Error by limited floating-point (x2)
810999408888888833569602076936910583555158505247065293524113031168;133579963
Error by limited floating-point (x8)
2326737888888882739301890030843707112889574955447311226724451090432;152390251
Error by limited floating-point (x3)
2778888888871981007014152874201195401408300641311199300391968702464;155810833
Error by limited floating-point (x19)
15111188888888925122195732008602567628522323430950253676602689847296;192542267
(ESTOS VALORES SON COMPLETAMENTE ERRONEOS:)
First 10 super-9 numbers:
Error by limited floating-point
8999999999999999844710088704;1000
4607999999999999920491565416448;2000
177146999999999994896138025041920;3000
2359295999999999959291681493221376;4000
Error by limited floating-point
8999999999999999939063878597132419072;10000
4607999999999999968800705841731798564864;20000
2359295999999999984025961390966680865210368;40000
Error by limited floating-point
....
(ctrl-c)
$
</pre>
Line 69 ⟶ 245:
{{libheader|System.Numerics}}
Done three ways, two with BigIntegers, and one with a UIint64 structure. More details on the "Mostly addition" method on the discussion page.
<
using System.Collections.Generic;
using BI = System.Numerics.BigInteger;
Line 189 ⟶ 365:
doOne("UInt64 structure mostly addition:", top, funF);
}
}</
{{out}}
Line 228 ⟶ 404:
=={{header|C}}==
{{libheader|GMP}}
<
#include <stdlib.h>
#include <string.h>
Line 254 ⟶ 430:
}
return 0;
}</
{{out}}
Line 279 ⟶ 455:
{{trans|D}}
There are insufficiant bits avalaible to calculate the super-5 or super-6 numbers without a biginteger library
<
#include <sstream>
#include <vector>
Line 322 ⟶ 498:
return 0;
}
</syntaxhighlight>
{{out}}
<pre>First 10 super-2 numbers:
Line 336 ⟶ 512:
{{libheader|GMP}}
{{trans|C}}
<
#include <gmpxx.h>
Line 358 ⟶ 534:
}
return 0;
}</
{{out}}
Line 382 ⟶ 558:
===Alternative ''not'' using GMP===
{{trans|C#}}
<
#include <sstream>
#include <chrono>
Line 452 ⟶ 628:
for (int i = 2; i <= 9; i++) fun(i);
}
</syntaxhighlight>
{{out}}
<pre>2: 19 31 69 81 105 106 107 119 127 131 0.002s
Line 468 ⟶ 644:
A more naïve implementation inspired by the Raku one, but without its use of parallelism; on my somewhat old and underpowered laptop, it gets through the basic task of 2 through 6 in about 6 seconds, then takes almost 40 to complete 7, and about six minutes for 8; with that growth rate, I didn't wait around for nine to complete.
<
(let [run (apply str (repeat d (str d)))]
(filter #(clojure.string/includes? (str (* d (Math/pow % d ))) run) (range))))
(doseq [d (range 2 9)]
(println (str d ": ") (take 10 (super d))))</
{{Out}}
<pre>2: (19 31 69 81 105 106 107 119 127 131)
Line 485 ⟶ 661:
=={{header|D}}==
{{trans|Go}}
<
import std.conv;
import std.stdio;
Line 514 ⟶ 690:
}
}
}</
{{out}}
<pre>First 10 super-2 numbers:
Line 542 ⟶ 718:
=={{header|F_Sharp|F#}}==
;The Function
<
// Generate Super-N numbers. Nigel Galloway: October 12th., 2019
let superD N=
Line 550 ⟶ 726:
let rec fL n=match (E-n%I).IsZero with true->true |_->if (E*10I)<n then false else fL (n/10I)
seq{1I..999999999999999999I}|>Seq.choose(fun n->if fL (G*n**N) then Some n else None)
</syntaxhighlight>
;The Task
<
superD 2 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn ""
superD 3 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn ""
Line 561 ⟶ 737:
superD 8 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn ""
superD 9 |> Seq.take 10 |> Seq.iter(printf "%A "); printfn ""
</syntaxhighlight>
{{out}}
<pre>
Line 575 ⟶ 751:
=={{header|Factor}}==
<
math.functions math.ranges math.text.utils prettyprint sequences
;
Line 592 ⟶ 768:
] with each ;
MAIN: super-d-demo</
{{out}}
<pre>
Line 610 ⟶ 786:
27257 272570 302693 323576 364509 502785 513675 537771 676657 678146
</pre>
=={{header|FreeBASIC}}==
{{trans|Visual Basic .NET}}
<syntaxhighlight lang="vbnet">Dim rd(7) As String = {"22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"}
For n As Integer = 2 To 9
Dim cont As Integer = 0
Dim j As Uinteger = 3
Print Using !"\nFirst 10 super-# numbers:"; n
Do
Dim k As Ulongint = n * (j ^ n)
Dim ix As Uinteger = Instr(Str(k), rd(n - 2))
If ix > 0 Then
cont += 1
Print j; " " ;
End If
j += 1
Loop Until cont = 10
Next n</syntaxhighlight>
=={{header|Fōrmulæ}}==
{{FormulaeEntry|page=https://formulae.org/?script=examples/Super-d_numbers}}
'''Solution'''
'''Case 1. Write a function/procedure/routine to find super-d numbers'''
[[File:Fōrmulæ - Super-d numbers 01.png]]
'''Case 2. For d=2 through d=9, use the routine to show the first 1 ssuper-d numbers'''
[[File:Fōrmulæ - Super-d numbers 02.png]]
[[File:Fōrmulæ - Super-d numbers 03.png]]
=={{header|Go}}==
Simple brute force approach and so not particularly quick - about 2.25 minutes on a Core i7.
<
import (
Line 655 ⟶ 858:
}
}
}</
{{out}}
Line 692 ⟶ 895:
</pre>
=={{header|Haskell}}==
<
import Data.Char (intToDigit)
Line 708 ⟶ 911:
("First 10 super-" ++) .
((++) . show <*> ((" : " ++) . show . take 10 . findSuperd)))
[2 .. 6]</
{{out}}
<pre>
Line 735 ⟶ 938:
=={{header|Java}}==
<
import java.math.BigInteger;
Line 770 ⟶ 973:
}
</syntaxhighlight>
{{out}}
Line 812 ⟶ 1,015:
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.
<
def power($b): . as $in | reduce range(0;$b) as $i (1; . * $in);
Line 835 ⟶ 1,038:
range(2; 8)
| "First 10 super-\(.) numbers:",
superd(10)</
{{out}}
<pre>
Line 909 ⟶ 1,112:
=={{header|Julia}}==
{{trans|Phix}}
<
println("First 10 super-$N numbers:")
count, j = 0, BigInt(3)
Line 926 ⟶ 1,129:
@time superd(n)
end
</
<pre>
First 10 super-2 numbers:
Line 956 ⟶ 1,159:
=={{header|Kotlin}}==
{{trans|Java}}
<
fun superD(d: Int, max: Int) {
Line 984 ⟶ 1,187:
superD(i, 10)
}
}</
{{out}}
<pre>First 10 super-2 numbers:
Line 1,021 ⟶ 1,224:
==={{header|Lua - using doubles}}===
Lua's default numeric type is IEEE-754 doubles, which are insufficient beyond d=5, but for reference:
<
local n, found = 0, {}
local dds = string.rep(d, d)
Line 1,030 ⟶ 1,233:
end
print("super-" .. d .. ": " .. table.concat(found,", "))
end</
{{out}}
<pre>super-2: 19, 31, 69, 81, 105, 106, 107, 119, 127, 131
Line 1,038 ⟶ 1,241:
==={{header|Lua - using lbc}}===
Using the lbc library to provide support for arbitrary-precision integers, which are sufficient for both task and extra-credit:
<
for i = 2, 9 do
local d, n, found = bc.new(i), bc.new(0), {}
Line 1,048 ⟶ 1,251:
end
print("super-" .. d:tostring() .. ": " .. table.concat(found,", "))
end</
{{out}}
<pre>super-2: 19, 31, 69, 81, 105, 106, 107, 119, 127, 131
Line 1,060 ⟶ 1,263:
=={{header|Mathematica}} / {{header|Wolfram Language}}==
<
SuperD[d_, m_] := Module[{n, res, num},
res = {};
Line 1,073 ⟶ 1,276:
res
]
Scan[Print[SuperD[#, 10]] &, Range[2, 6]]</
{{out}}
<pre>{19,31,69,81,105,106,107,119,127,131}
Line 1,085 ⟶ 1,288:
Using only the standard library, we would be limited to "d = 2, 3, 4". So, here is the program using the third-party library "bignum".
<
import bignum
Line 1,103 ⟶ 1,306:
echo "First 10 super-$# numbers:".format(d)
echo toSeq(superDNumbers(d, 10)).join(" ")
echo "Time: ", getTime() - t0</
{{out}}
Line 1,127 ⟶ 1,330:
{{works with|Free Pascal}}
gmp is fast.Same brute force as [http://rosettacode.org/wiki/Super-d_numbers#Go Go]
<
uses
sysutils,gmp;
Line 1,165 ⟶ 1,368:
end;
mpz_clear(test);
End.</
{{out}}
<pre>Finding 22 in 2*i**2
Line 1,199 ⟶ 1,402:
=={{header|Perl}}==
<
use warnings;
use bigint;
Line 1,220 ⟶ 1,423:
}
say "\nFirst 10 super-$_ numbers:\n", join ' ', super($_) for 2..6;</
<pre>
Line 1,240 ⟶ 1,443:
=={{header|Phix}}==
{{trans|Go}}
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">atom</span> <span style="color: #000000;">t0</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">time</span><span style="color: #0000FF;">()</span>
<span style="color: #004080;">mpz</span> <span style="color: #000000;">k</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpz_init</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span> <span style="color: #008080;">to</span> <span style="color: #008080;">iff</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()=</span><span style="color: #004600;">JS</span><span style="color: #0000FF;">?</span><span style="color: #000000;">7</span><span style="color: #0000FF;">:</span><span style="color: #000000;">9</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"First 10 super-%d numbers:\n"</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">count</span> <span style="color: #0000FF;">:=</span> <span style="color: #000000;">0</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">j</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">3</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">tgt</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">repeat</span><span style="color: #0000FF;">(</span><span style="color: #008000;">'0'</span><span style="color: #0000FF;">+</span><span style="color: #000000;">i</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">while</span> <span style="color: #000000;">count</span><span style="color: #0000FF;"><</span><span style="color: #000000;">10</span> <span style="color: #008080;">do</span>
<span style="color: #7060A8;">mpz_ui_pow_ui</span><span style="color: #0000FF;">(</span><span style="color: #000000;">k</span><span style="color: #0000FF;">,</span><span style="color: #000000;">j</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">mpz_mul_si</span><span style="color: #0000FF;">(</span><span style="color: #000000;">k</span><span style="color: #0000FF;">,</span><span style="color: #000000;">k</span><span style="color: #0000FF;">,</span><span style="color: #000000;">i</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">string</span> <span style="color: #000000;">s</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">mpz_get_str</span><span style="color: #0000FF;">(</span><span style="color: #000000;">k</span><span style="color: #0000FF;">)</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">ix</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tgt</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">if</span> <span style="color: #000000;">ix</span> <span style="color: #008080;">then</span>
<span style="color: #000000;">count</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d "</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">j</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<span style="color: #000000;">j</span> <span style="color: #0000FF;">+=</span> <span style="color: #000000;">1</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"\nfound in %s\n\n"</span><span style="color: #0000FF;">,</span> <span style="color: #0000FF;">{</span><span style="color: #7060A8;">elapsed</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">time</span><span style="color: #0000FF;">()-</span><span style="color: #000000;">t0</span><span style="color: #0000FF;">)})</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #000000;">main</span><span style="color: #0000FF;">()</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
Line 1,296 ⟶ 1,502:
First 10 super-9 numbers:
17546133 <killed>
</pre>
Since its actually about 3 times faster under pwa/p2js, I let that one run, just the once, keeping the above capped at 7 for ~11s:
<pre>
...
First 10 super-8 numbers:
185423 641519 1551728 1854230 6415190 12043464 12147605 15517280 16561735 18542300
found in 1 minute and 22s
First 10 super-9 numbers:
17546133 32613656 93568867 107225764 109255734 113315082 121251742 175461330 180917907 182557181
found in 16 minutes and 6s
</pre>
=={{header|Python}}==
===Procedural===
<
def superd(d):
Line 1,312 ⟶ 1,529:
if __name__ == '__main__':
for d in range(2, 9):
print(f"{d}:", ', '.join(str(n) for n in islice(superd(d), 10)))</
{{out}}
Line 1,324 ⟶ 1,541:
===Functional===
<
from itertools import count, islice
Line 1,462 ⟶ 1,679:
# MAIN ---
if __name__ == '__main__':
main()</
{{Out}}
<pre>1 :: Super-d is defined only for integers drawn from {2..9}
Line 1,471 ⟶ 1,688:
First 10 super-6: [27257,272570,302693,323576,364509,502785,513675,537771,676657,678146]</pre>
=={{header|Quackery}}==
<code>from</code>, <code>index</code> and <code>end</code> are defined at [[Loops/Increment loop index within loop body#Quackery]].
<syntaxhighlight lang="Quackery"> [ over findseq swap found ] is hasseq ( [ x --> b )
[ [] swap
[ 10 /mod
rot join swap
dup 0 = until ]
drop ] is digits ( n --> [ )
[ over ** over * digits
swap dup of hasseq ] is superd ( n --> b )
[] 5 times
[ [] 1 from
[ i^ 2 + index
superd if [ index join ]
dup size 10 = if end ]
nested join ]
witheach
[ i^ 2 + echo say " -> " echo cr ]</syntaxhighlight>
{{out}}
<pre>2 -> [ 19 31 69 81 105 106 107 119 127 131 ]
3 -> [ 261 462 471 481 558 753 1036 1046 1471 1645 ]
4 -> [ 1168 4972 7423 7752 8431 10267 11317 11487 11549 11680 ]
5 -> [ 4602 5517 7539 12955 14555 20137 20379 26629 32767 35689 ]
6 -> [ 27257 272570 302693 323576 364509 502785 513675 537771 676657 678146 ]
</pre>
=={{header|R}}==
Line 1,477 ⟶ 1,726:
Library is necessary to go beyond super-4 numbers. Indeed [https://cran.r-project.org/web/packages/Rmpfr/Rmpfr.pdf Rmpfr] allows to augment precision for floating point numbers. I didn't go for extra task, because it took some minutes for super-6 numbers.
<
options(scipen = 999)
Line 1,523 ⟶ 1,772:
for(d in 2:6){find_super_d_number(d, N = 10)}
</syntaxhighlight>
{{out}}
Line 1,544 ⟶ 1,793:
2 - 6 take a few seconds, 7 about 17 seconds, 8 about 90... 9, bleh... around 700 seconds.
<syntaxhighlight lang="raku"
my \run = d x d;
^∞ .hyper.grep: -> \n { (d * n ** d).Str.contains: run }
Line 1,552 ⟶ 1,801:
my $now = now;
put "\nFirst 10 super-$_ numbers:\n{.&super[^10]}\n{(now - $now).round(.1)} sec."
}</
<pre>First 10 super-2 numbers:
Line 1,587 ⟶ 1,836:
=={{header|REXX}}==
<
numeric digits 100 /*ensure enough decimal digs for calc. */
parse arg n LO HI . /*obtain optional arguments from the CL*/
Line 1,603 ⟶ 1,852:
say center(' the first ' n " super-"d 'numbers ', digits(), "═")
say $
end /*d*/ /*stick a fork in it, we're all done. */</
{{out|output|text= when using the default inputs:}}
<pre>
Line 1,632 ⟶ 1,881:
=={{header|Ruby}}==
<
rep = d.to_s * d
print "#{d}: "
puts (2..).lazy.select{|n| (d * n**d).to_s.include?(rep) }.first(10).join(", ")
end
</syntaxhighlight>
{{out}}
<pre>2: 19, 31, 69, 81, 105, 106, 107, 119, 127, 131
Line 1,651 ⟶ 1,900:
=={{header|Rust}}==
<
// rug = "1.9"
Line 1,679 ⟶ 1,928:
print_super_d_numbers(d, 10);
}
}</
{{out}}
Line 1,702 ⟶ 1,951:
=={{header|Sidef}}==
<
var D = Str(d)*d
1..Inf -> lazy.grep {|n| Str(d * n**d).contains(D) }
Line 1,709 ⟶ 1,958:
for d in (2..8) {
say ("#{d}: ", super_d(d).first(10))
}</
{{out}}
<pre>
Line 1,725 ⟶ 1,974:
{{libheader|AttaSwift BigInt}}
<
import Foundation
Line 1,757 ⟶ 2,006:
print()
print()
}</
{{out}}
Line 1,787 ⟶ 2,036:
=={{header|Visual Basic .NET}}==
{{trans|D}}
<
Module Module1
Line 1,819 ⟶ 2,068:
End Sub
End Module</
{{out}}
<pre>First 10 super-2 numbers:
Line 1,847 ⟶ 2,096:
=={{header|Wren}}==
{{trans|Go}}
===CLI (BigInt)===
{{libheader|Wren-big}}
{{libheader|Wren-fmt}}
Managed to get up to 8 but too slow for 9.
<
import "./fmt" for Fmt
var start = System.clock
Line 1,872 ⟶ 2,122:
j = j.inc
}
}</
{{out}}
Line 1,903 ⟶ 2,153:
185423 641519 1551728 1854230 6415190 12043464 12147605 15517280 16561735 18542300
found in 434.536825 seconds
</pre>
===Embedded (GMP)===
{{libheader|Wren-gmp}}
Much sprightlier with 8 now being reached in 11.7 seconds and 9 in 126.5 seconds.
<syntaxhighlight lang="wren">/* Super-d_numbers_2.wren */
import "./gmp" for Mpz
import "./fmt" for Fmt
var start = System.clock
var rd = ["22", "333", "4444", "55555", "666666", "7777777", "88888888", "999999999"]
for (i in 2..9) {
Fmt.print("First 10 super-$d numbers:", i)
var count = 0
var j = Mpz.three
var k = Mpz.new()
while (true) {
k.pow(j, i).mul(i)
var ix = k.toString.indexOf(rd[i-2])
if (ix >= 0) {
count = count + 1
Fmt.write("$i ", j)
if (count == 10) {
Fmt.print("\nfound in $f seconds\n", System.clock - start)
break
}
}
j.inc
}
}</syntaxhighlight>
{{out}}
<pre>
First 10 super-2 numbers:
19 31 69 81 105 106 107 119 127 131
found in 0.000222 seconds
First 10 super-3 numbers:
261 462 471 481 558 753 1036 1046 1471 1645
found in 0.001222 seconds
First 10 super-4 numbers:
1168 4972 7423 7752 8431 10267 11317 11487 11549 11680
found in 0.007386 seconds
First 10 super-5 numbers:
4602 5517 7539 12955 14555 20137 20379 26629 32767 35689
found in 0.024863 seconds
First 10 super-6 numbers:
27257 272570 302693 323576 364509 502785 513675 537771 676657 678146
found in 0.339837 seconds
First 10 super-7 numbers:
140997 490996 1184321 1259609 1409970 1783166 1886654 1977538 2457756 2714763
found in 1.684412 seconds
First 10 super-8 numbers:
185423 641519 1551728 1854230 6415190 12043464 12147605 15517280 16561735 18542300
found in 11.695570 seconds
First 10 super-9 numbers:
17546133 32613656 93568867 107225764 109255734 113315082 121251742 175461330 180917907 182557181
found in 126.454911 seconds
</pre>
=={{header|zkl}}==
{{libheader|GMP}} GNU Multiple Precision Arithmetic Library
<
fcn superDW(d){
Line 1,914 ⟶ 2,228:
{ BI(n).pow(d).mul(d).toString().holds(digits) and n or Void.Skip });
}
foreach d in ([2..8]){ println(d," : ",superDW(d).walk(10).concat(" ")) }</
{{out}}
<pre>
|