Penholodigital squares: Difference between revisions
Content added Content deleted
No edit summary |
(Added AppleScript.) |
||
Line 48: | Line 48: | ||
;* [[oeis:A036744|OEIS:A036744 - Penholodigital squares in base 10]] |
;* [[oeis:A036744|OEIS:A036744 - Penholodigital squares in base 10]] |
||
;* [[First_perfect_square_in_base_n_with_n_unique_digits|Related task: First perfect square in base n with n unique digits]] |
;* [[First_perfect_square_in_base_n_with_n_unique_digits|Related task: First perfect square in base n with n unique digits]] |
||
=={{header|AppleScript}}== |
|||
<syntaxhighlight lang="applescript">on penholodigitalSquares(base) |
|||
set digits to "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|||
set output to {} |
|||
set minFromDigits to 1 |
|||
repeat with d from 2 to (base - 1) |
|||
set minFromDigits to minFromDigits * base + d |
|||
end repeat |
|||
set maxFromDigits to base - 1 |
|||
repeat with d from (base - 2) to 1 by -1 |
|||
set maxFromDigits to maxFromDigits * base + d |
|||
end repeat |
|||
repeat with sqrt from (round (minFromDigits ^ 0.5) rounding up) to (maxFromDigits ^ 0.5 div 1) |
|||
set n to sqrt * sqrt |
|||
set usedDigitValues to {0} |
|||
set OKSoFar to true |
|||
repeat (base - 2) times -- until (n < base) |
|||
set d to n mod base |
|||
if (d is in usedDigitValues) then |
|||
set OKSoFar to false |
|||
exit repeat |
|||
end if |
|||
set usedDigitValues's end to d |
|||
set n to n div base |
|||
end repeat |
|||
if ((OKSoFar) and (n is not in usedDigitValues)) then ¬ |
|||
set end of output to {intToBase(sqrt, base), intToBase(sqrt * sqrt, base)} |
|||
end repeat |
|||
return output |
|||
end penholodigitalSquares |
|||
on intToBase(int, base) |
|||
if ((int < 0) or (int mod 1 > 0) or (base < 2) or (base > 36)) then return missing value |
|||
set digits to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|||
set output to digits's character (int mod base + 1) |
|||
repeat until (int < base) |
|||
set int to int div base |
|||
set output to digits's character (int mod base + 1) & output |
|||
end repeat |
|||
return output |
|||
end intToBase |
|||
on join(lst, delim) |
|||
set astid to AppleScript's text item delimiters |
|||
set AppleScript's text item delimiters to delim |
|||
set txt to lst as text |
|||
set AppleScript's text item delimiters to astid |
|||
return txt |
|||
end join |
|||
on task() |
|||
set output to {} |
|||
repeat with base from 9 to 14 |
|||
set results to penholodigitalSquares(base) |
|||
set resultCount to (count results) |
|||
if (resultCount > 1) then |
|||
set output's end to linefeed & "There are " & resultCount & ¬ |
|||
(" penholodigital squares in base " & base & ":") |
|||
if (base < 13) then |
|||
repeat with i from 1 to resultCount by 3 |
|||
set row to {} |
|||
set k to i + 2 |
|||
if (k > resultCount) then set k to resultCount |
|||
repeat with j from i to k |
|||
set end of row to join(results's item j, " ^ 2 = ") |
|||
end repeat |
|||
set output's end to join(row, " ") |
|||
end repeat |
|||
else |
|||
set output's end to "First: " & join(results's beginning, " ^ 2 = ") & ¬ |
|||
(" Last: " & join(results's end, " ^ 2 = ")) |
|||
end if |
|||
else if (resultCount = 1) then |
|||
set output's end to linefeed & "There is 1 penholodigital square in base " & ¬ |
|||
base & ":" |
|||
set output's end to join(results's beginning, " ^ 2 = ") |
|||
else |
|||
set output's end to linefeed & "There are no penholodigital squares in base " & base |
|||
end if |
|||
end repeat |
|||
return join(output, linefeed) |
|||
end task |
|||
task()</syntaxhighlight> |
|||
{{output}} |
|||
<syntaxhighlight lang="applescript">" |
|||
There are 10 penholodigital squares in base 9: |
|||
3825 ^ 2 = 16328547 3847 ^ 2 = 16523874 4617 ^ 2 = 23875614 |
|||
4761 ^ 2 = 25487631 6561 ^ 2 = 47865231 6574 ^ 2 = 48162537 |
|||
6844 ^ 2 = 53184267 7285 ^ 2 = 58624317 7821 ^ 2 = 68573241 |
|||
8554 ^ 2 = 82314657 |
|||
There are 30 penholodigital squares in base 10: |
|||
11826 ^ 2 = 139854276 12363 ^ 2 = 152843769 12543 ^ 2 = 157326849 |
|||
14676 ^ 2 = 215384976 15681 ^ 2 = 245893761 15963 ^ 2 = 254817369 |
|||
18072 ^ 2 = 326597184 19023 ^ 2 = 361874529 19377 ^ 2 = 375468129 |
|||
19569 ^ 2 = 382945761 19629 ^ 2 = 385297641 20316 ^ 2 = 412739856 |
|||
22887 ^ 2 = 523814769 23019 ^ 2 = 529874361 23178 ^ 2 = 537219684 |
|||
23439 ^ 2 = 549386721 24237 ^ 2 = 587432169 24276 ^ 2 = 589324176 |
|||
24441 ^ 2 = 597362481 24807 ^ 2 = 615387249 25059 ^ 2 = 627953481 |
|||
25572 ^ 2 = 653927184 25941 ^ 2 = 672935481 26409 ^ 2 = 697435281 |
|||
26733 ^ 2 = 714653289 27129 ^ 2 = 735982641 27273 ^ 2 = 743816529 |
|||
29034 ^ 2 = 842973156 29106 ^ 2 = 847159236 30384 ^ 2 = 923187456 |
|||
There are 20 penholodigital squares in base 11: |
|||
42045 ^ 2 = 165742A893 43152 ^ 2 = 173A652894 44926 ^ 2 = 18792A6453 |
|||
47149 ^ 2 = 1A67395824 47257 ^ 2 = 1A76392485 52071 ^ 2 = 249A758631 |
|||
54457 ^ 2 = 2719634A85 55979 ^ 2 = 286A795314 59597 ^ 2 = 314672A895 |
|||
632A4 ^ 2 = 3671A89245 64069 ^ 2 = 376198A254 68335 ^ 2 = 41697528A3 |
|||
71485 ^ 2 = 46928A7153 81196 ^ 2 = 5A79286413 83608 ^ 2 = 632A741859 |
|||
86074 ^ 2 = 6713498A25 89468 ^ 2 = 7148563A29 91429 ^ 2 = 76315982A4 |
|||
93319 ^ 2 = 795186A234 A3A39 ^ 2 = 983251A764 |
|||
There are 23 penholodigital squares in base 12: |
|||
117789 ^ 2 = 135B7482A69 16357B ^ 2 = 23A5B976481 16762B ^ 2 = 24AB5379861 |
|||
16906B ^ 2 = 25386749BA1 173434 ^ 2 = 26B859A3714 178278 ^ 2 = 2835BA17694 |
|||
1A1993 ^ 2 = 34A8125B769 1A3595 ^ 2 = 354A279B681 1B0451 ^ 2 = 3824B7569A1 |
|||
1B7545 ^ 2 = 3A5B2487961 2084A9 ^ 2 = 42A1583B769 235273 ^ 2 = 5287BA13469 |
|||
2528B5 ^ 2 = 5B23A879641 25B564 ^ 2 = 62937B5A814 262174 ^ 2 = 63A8527B194 |
|||
285A44 ^ 2 = 73B615A8294 29A977 ^ 2 = 7B9284A5361 2A7617 ^ 2 = 83AB5479261 |
|||
2B0144 ^ 2 = 8617B35A294 307381 ^ 2 = 93825A67B41 310828 ^ 2 = 96528AB7314 |
|||
319488 ^ 2 = 9AB65823714 319A37 ^ 2 = 9B2573468A1 |
|||
There are no penholodigital squares in base 13 |
|||
There are 160 penholodigital squares in base 14: |
|||
First: 1129535 ^ 2 = 126A84D79C53B Last: 3A03226 ^ 2 = DB3962A7541C8"</syntaxhighlight> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |