Penholodigital squares: Difference between revisions

m
Undo revision 336537 by Wherrera (talk)
(julia example)
m (Undo revision 336537 by Wherrera (talk))
Tag: Undo
Line 243:
fec81b69573da24=3fd8f786²
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)
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:
58² = 3825 58² = 3847 64² = 4617
65² = 4761 76² = 6561 76² = 6574
78² = 6844 81² = 7285 83² = 7821
87² = 8554
 
There is a total of 30 penholodigital squares in base 10:
108² = 11826 111² = 12363 111² = 12543
121² = 14676 125² = 15681 126² = 15963
134² = 18072 137² = 19023 139² = 19377
139² = 19569 140² = 19629 142² = 20316
151² = 22887 151² = 23019 152² = 23178
153² = 23439 155² = 24237 155² = 24276
156² = 24441 157² = 24807 158² = 25059
159² = 25572 161² = 25941 162² = 26409
163² = 26733 164² = 27129 165² = 27273
170² = 29034 170² = 29106 174² = 30384
 
 
There is a total of 20 penholodigital squares in base 11:
205² = 42045 208² = 43152 211² = 44926
217² = 47149 218² = 47257 230² = 52071
236² = 54457 239² = 55979 247² = 59597
256² = 632a4 258² = 64069 266² = 68335
274² = 71485 293² = 81196 298² = 83608
2a1² = 86074 2a8² = 89468 302² = 91429
305² = 93319 324² = a3a39
 
There is a total of 23 penholodigital squares in base 12:
383² = 117789 433² = 16357b 439² = 16762b
43b² = 16906b 448² = 173434 452² = 178278
485² = 1a1993 487² = 1a3595 497² = 1b0451
4a3² = 1b7545 4b7² = 2084a9 52a² = 235273
54a² = 2528b5 558² = 25b564 55b² = 262174
584² = 285a44 59a² = 29a977 5a7² = 2a7617
5b0² = 2b0144 607² = 307381 610² = 310828
619² = 319488 619² = 319a37
 
There is a total of 0 penholodigital squares in base 13:
 
 
There is a total of 160 penholodigital squares in base 14:
1082² = 1129535 1cdb² = 3a03226
 
There is a total of 419 penholodigital squares in base 15:
2086² = 4240c58 3ceb² = ee25e4a
 
There is a total of 740 penholodigital squares in base 16:
4221² = 11156eb6 7fd8² = 3fd8f786
</pre>
 
 
=={{header|Pascal}}==
4,102

edits