How to resolve the algorithm First perfect square in base n with n unique digits step by step in the XPL0 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm First perfect square in base n with n unique digits step by step in the XPL0 programming language

Table of Contents

Problem Statement

Find the first perfect square in a given base N that has at least N digits and exactly N significant unique digits when expressed in base N. E.G. In base 10, the first perfect square with at least 10 unique digits is 1026753849 (32043²). You may use analytical methods to reduce the search space, but the code must do a search. Do not use magic numbers or just feed the code the answer to verify it is correct.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm First perfect square in base n with n unique digits step by step in the XPL0 programming language

Source code in the xpl0 programming language

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<
    ];
return Used = 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.;
]

  

You may also check:How to resolve the algorithm Diversity prediction theorem step by step in the Phix programming language
You may also check:How to resolve the algorithm Boustrophedon transform step by step in the Perl programming language
You may also check:How to resolve the algorithm Vigenère cipher/Cryptanalysis step by step in the Haskell programming language
You may also check:How to resolve the algorithm Largest int from concatenated ints step by step in the VBScript programming language
You may also check:How to resolve the algorithm SEDOLs step by step in the langur programming language