Penholodigital squares: Difference between revisions

Content added Content deleted
m (→‎{{header|Free Pascal}}: Calc GCD of deltas between the roots.Mostly not 1.)
Line 642: Line 642:
There is a total of 740 penholodigital squares in base 16:
There is a total of 740 penholodigital squares in base 16:
11156EB6² = 123DA7F85BCE964, 3FD8F786² = FEC81B69573DA24</pre>
11156EB6² = 123DA7F85BCE964, 3FD8F786² = FEC81B69573DA24</pre>

=={{header|RPL}}==
{{works with|Halcyon Calc|4.2.7}}
{| class="wikitable"
! Code
! Comments
|-
|
"0123456789ABCDEF" 'Digits' STO
≪ → base
≪ "" SWAP
WHILE DUP REPEAT
DUP base MOD
Digits OVER 1 + DUP SUB
4 ROLL + ROT ROT - base / RND
END DROP
≫ ≫ 'D→BAS' STO
≪ → base
≪ 0 1 SIZE FOR j
base * OVER j j SUB Digits SWAP POS 1 - +
NEXT SWAP DROP
≫ ≫ 'BAS→D' STO
≪ → number base digits
≪ IF number "0" POS
THEN 0
ELSE
{} base + 0 CON 1 1 PUT
1 number SIZE FOR j
Digits number j DUP SUB POS 1 PUT
NEXT CNRM base ==
END
≫ ≫ 'PHD?' STO
≪ 0 0 → base first last
≪ 0 1 SF
Digits 2 base SUB base BAS→D√ FLOOR
"FEDCBA987654321" 17 base - 15 SUB base BAS→D√ CEIL
FOR n
n SQ base D→BAS
IF base PHD?
THEN 1 + n 'last' STO IF 1 FS?C THEN n 'first' STO END
END
NEXT
IF first THEN
first base D→BAS "^2 = " + first SQ base D→BAS +
last base D→BAS "^2 = " + last SQ base D→BAS +
END
≫ ≫ 'PHDSQ' STO
|
Constant
''( n base -- "###" )''
''( "###" base -- n )''
''( "###" base -- boolean )''
Initialize variables o/w an array of counters
the sum of counters must equal base
''( base -- #PHD "first PHD" "last PHD" )''
start search with "123..b"
end search with "b..321"
Display detailed results
|}
The following lines of command deliver what is required:
9 PHDSQ
10 PHDSQ
11 PHDSQ
12 PHDSQ
{{out}}
<pre>
12: 10
11: "3825^2 = 16328547"
10: "8554^2 = 82314657"
9: 30
8: "11826^2 = 139854276"
7: "30384^2 = 923187456"
6: 20
5: "42045^2 = 165742A893"
4: "A3A39^2 = 983251A764"
3: 23
2: "117789^2 = 135B7482A69"
1: "319A37^2 = 9B2573468A1"
</pre>


=={{header|Wren}}==
=={{header|Wren}}==