First perfect square in base n with n unique digits: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Thundergnat moved page First perfect square in base N with N unique digits to First perfect square in base n with n unique digits: Follow normal task title capitalization policy) |
|||
Line 526: | Line 526: | ||
</pre> |
</pre> |
||
=={{header|Forth}}== |
|||
<lang Forth> |
|||
: 2^ 1 swap lshift ; |
|||
: sq s" dup *" evaluate ; immediate |
|||
: min-root ( -- n ) \ minimum root that can be pandigitial |
|||
base @ s>f fdup 1e f- 0.5e f* f** f>s ; |
|||
: pandigital? ( n -- f ) |
|||
0 swap \ bitmask |
|||
begin |
|||
base @ /mod |
|||
>r 2^ or r> |
|||
dup 0= until drop |
|||
base @ 2^ 1- = ; |
|||
: panroot ( -- n ) \ get the minimum square root using the variable BASE. |
|||
min-root 1- begin |
|||
1+ |
|||
dup sq pandigital? until ; |
|||
: d. ( n w -- ) \ show number in decimal |
|||
base @ >r decimal .r r> base ! ; |
|||
: showsquares ( -- ) |
|||
base @ 17 2 do |
|||
i base ! |
|||
cr i 2 d. 3 spaces panroot dup 10 .r ." ² = " sq . |
|||
loop base ! ; |
|||
</lang> |
|||
{{Out}} |
|||
<pre> |
|||
showsquares |
|||
2 10² = 100 |
|||
3 22² = 2101 |
|||
4 33² = 3201 |
|||
5 243² = 132304 |
|||
6 523² = 452013 |
|||
7 1431² = 2450361 |
|||
8 3344² = 13675420 |
|||
9 11642² = 136802574 |
|||
10 32043² = 1026753849 |
|||
11 111453² = 1240A536789 |
|||
12 3966B9² = 124A7B538609 |
|||
13 3828943² = 10254773CA86B9 |
|||
14 3A9DB7C² = 10269B8C57D3A4 |
|||
15 1012B857² = 102597BACE836D4 |
|||
16 404A9D9B² = 1025648CFEA37BD9 ok |
|||
</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
This takes advantage of major optimizations described by Nigel Galloway and Thundergnat (inspired by initial pattern analysis by Hout) in the Discussion page and a minor optimization contributed by myself. |
This takes advantage of major optimizations described by Nigel Galloway and Thundergnat (inspired by initial pattern analysis by Hout) in the Discussion page and a minor optimization contributed by myself. |
||
Line 792: | Line 842: | ||
Base 28: 58a3ckp3n4cqd7² = 1023456cgjbirqedhp98kmoan7fl in 911.059s |
Base 28: 58a3ckp3n4cqd7² = 1023456cgjbirqedhp98kmoan7fl in 911.059s |
||
</pre> |
</pre> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
{{trans|F#}} |
{{trans|F#}} |