Penholodigital squares: Difference between revisions

Added Wren
m (add some emphasis since people are missing it)
(Added Wren)
Line 209:
There is a total of 740 penholodigital squares in base 16:
11156EB6² = 123DA7F85BCE964, 3FD8F786² = FEC81B69573DA24</pre>
 
=={{header|Wren}}==
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
This is limited to base 14 as base 15 would overflow Wren's safe integer limit of 2^53.
<syntaxhighlight lang="ecmascript">import "./math" for Int
import "./fmt" for Conv, Fmt
 
var primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]
var digits = "123456789ABCD"
 
for (b in 9..14) {
var master = 1
for (d in 1...b) master = master * primes[d-1]
var phd = []
var max = Conv.atoi(digits[(b-2)..0].join(), b).sqrt.floor
for (i in 1..max) {
var sq = i * i
if (b == 10 && (sq % 3) != 0) continue
var digs = Int.digits(sq, b)
if (digs.contains(0)) continue
var key = 1
for (dig in digs) key = key * primes[dig-1]
if (key == master) phd.add(i)
}
System.print("There is a total of %(phd.count) penholodigital squares in base %(b):")
if (b > 13) phd = [phd[0], phd[-1]]
for (i in 0...phd.count) {
Fmt.write("$s² = $s ", Conv.Itoa(phd[i], b), Conv.Itoa(phd[i] * phd[i], b))
if ((i + 1) % 3 == 0) System.print()
}
if (phd.count % 3 != 0) System.print()
System.print()
}</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
</pre>
9,476

edits