Penholodigital squares: Difference between revisions
Content added Content deleted
Tag: Undo |
(julia example) |
||
Line 243: | Line 243: | ||
fec81b69573da24=3fd8f786² |
fec81b69573da24=3fd8f786² |
||
NB. this is getting to be obnoxiously long in terms of time...</syntaxhighlight> |
NB. this is getting to be obnoxiously long in terms of time...</syntaxhighlight> |
||
=={{header|Julia}}== |
|||
<syntaxhighlight lang="julia">""" rosettacode.org task Penholodigital_squares """ |
|||
function penholodigital(base) |
|||
penholodigitals = Int[] |
|||
hi, lo = isqrt(evalpoly(base, 1:base-1)), isqrt(evalpoly(base, base-1:-1:1)) |
|||
for n in lo:hi |
|||
dig = digits(n * n; base) |
|||
0 in dig && continue |
|||
if all(i -> count(==(i), dig) == 1, 1:base-1) |
|||
push!(penholodigitals, n * n) |
|||
end |
|||
end |
|||
return penholodigitals |
|||
end |
|||
for j in 9:16 |
|||
allpen = penholodigital(j) |
|||
println("\n\nThere is a total of $(length(allpen)) penholodigital squares in base $j:") |
|||
for (i, n) in (j < 14 ? enumerate(allpen) : enumerate([allpen[begin], allpen[end]])) |
|||
print(string(isqrt(n), base=j), "² = ", string(n, base=j), i %3 == 0 ? "\n" : " ") |
|||
end |
|||
end |
|||
</syntaxhighlight>{{out}} |
|||
<pre> |
|||
There is a total of 10 penholodigital squares in base 9: |
|||
3825² = 16328547 3847² = 16523874 4617² = 23875614 |
|||
4761² = 25487631 6561² = 47865231 6574² = 48162537 |
|||
6844² = 53184267 7285² = 58624317 7821² = 68573241 |
|||
8554² = 82314657 |
|||
There is a total of 30 penholodigital squares in base 10: |
|||
11826² = 139854276 12363² = 152843769 12543² = 157326849 |
|||
14676² = 215384976 15681² = 245893761 15963² = 254817369 |
|||
18072² = 326597184 19023² = 361874529 19377² = 375468129 |
|||
19569² = 382945761 19629² = 385297641 20316² = 412739856 |
|||
22887² = 523814769 23019² = 529874361 23178² = 537219684 |
|||
23439² = 549386721 24237² = 587432169 24276² = 589324176 |
|||
24441² = 597362481 24807² = 615387249 25059² = 627953481 |
|||
25572² = 653927184 25941² = 672935481 26409² = 697435281 |
|||
26733² = 714653289 27129² = 735982641 27273² = 743816529 |
|||
29034² = 842973156 29106² = 847159236 30384² = 923187456 |
|||
There is a total of 20 penholodigital squares in base 11: |
|||
42045² = 165742a893 43152² = 173a652894 44926² = 18792a6453 |
|||
47149² = 1a67395824 47257² = 1a76392485 52071² = 249a758631 |
|||
54457² = 2719634a85 55979² = 286a795314 59597² = 314672a895 |
|||
632a4² = 3671a89245 64069² = 376198a254 68335² = 41697528a3 |
|||
71485² = 46928a7153 81196² = 5a79286413 83608² = 632a741859 |
|||
86074² = 6713498a25 89468² = 7148563a29 91429² = 76315982a4 |
|||
93319² = 795186a234 a3a39² = 983251a764 |
|||
There is a total of 23 penholodigital squares in base 12: |
|||
117789² = 135b7482a69 16357b² = 23a5b976481 16762b² = 24ab5379861 |
|||
16906b² = 25386749ba1 173434² = 26b859a3714 178278² = 2835ba17694 |
|||
1a1993² = 34a8125b769 1a3595² = 354a279b681 1b0451² = 3824b7569a1 |
|||
1b7545² = 3a5b2487961 2084a9² = 42a1583b769 235273² = 5287ba13469 |
|||
2528b5² = 5b23a879641 25b564² = 62937b5a814 262174² = 63a8527b194 |
|||
285a44² = 73b615a8294 29a977² = 7b9284a5361 2a7617² = 83ab5479261 |
|||
2b0144² = 8617b35a294 307381² = 93825a67b41 310828² = 96528ab7314 |
|||
319488² = 9ab65823714 319a37² = 9b2573468a1 |
|||
There is a total of 0 penholodigital squares in base 13: |
|||
There is a total of 160 penholodigital squares in base 14: |
|||
1129535² = 126a84d79c53b 3a03226² = db3962a7541c8 |
|||
There is a total of 419 penholodigital squares in base 15: |
|||
4240c58² = 12378da5b6ec94 ee25e4a² = ed4c93285671ba |
|||
There is a total of 740 penholodigital squares in base 16: |
|||
11156eb6² = 123da7f85bce964 3fd8f786² = fec81b69573da24 |
|||
</pre> |
|||
=={{header|Pascal}}== |
=={{header|Pascal}}== |