First perfect square in base n with n unique digits: Difference between revisions

Added XPL0 example.
m (syntax highlighting fixup automation)
(Added XPL0 example.)
Line 3,979:
Base 20: 49dgih5d3g² = 1024e7cdi3hb695fja8g in 696.567s
Base 21: 4c9he5fe27f² = 1023457dg9hi8j6b6kceaf in 735.738s
</pre>
 
=={{header|XPL0}}==
Base 14 is the largest that can be calculated using double precision
floating point (14^13 = 7.9e14; 15^14 = 2.9e16). Runs in about 38 seconds
on Pi4.
<syntaxhighlight lang "XPL0">real Base; \Number Base used [2..14]
 
proc NumOut(N); \Display N in the specified Base
real N;
int Remain;
[Remain:= fix(Mod(N, Base));
N:= Floor(N/Base);
if N # 0. then NumOut(N);
ChOut(0, Remain + (if Remain <= 9 then ^0 else ^A-10));
];
 
func Pandigital(N); \Return 'true' if N is pandigital
real N;
int Used, Remain;
[Used:= 0;
while N # 0. do
[Remain:= fix(Mod(N, Base));
N:= Floor(N/Base);
Used:= Used ! 1<<Remain;
];
return Used = 1<<fix(Base) - 1;
];
 
real N;
[Base:= 2.;
Format(2, 0);
repeat N:= Floor(Sqrt(Pow(Base, Base-1.)));
loop [if Pandigital(N*N) then
[RlOut(0, Base); Text(0, ": ");
NumOut(N); Text(0, "^^2 = ");
NumOut(N*N); CrLf(0);
quit;
];
N:= N + 1.;
];
Base:= Base + 1.;
until Base > 14.;
]</syntaxhighlight>
{{out}}
<pre>
2: 10^2 = 100
3: 22^2 = 2101
4: 33^2 = 3201
5: 243^2 = 132304
6: 523^2 = 452013
7: 1431^2 = 2450361
8: 3344^2 = 13675420
9: 11642^2 = 136802574
10: 32043^2 = 1026753849
11: 111453^2 = 1240A536789
12: 3966B9^2 = 124A7B538609
13: 3828943^2 = 10254773CA86B9
14: 3A9DB7C^2 = 10269B8C57D3A4
</pre>
 
295

edits