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

m
→‎{{header|REXX}}: made the two REXX programs more generic as far as specifying arguments (parameters).
m (→‎{{header|REXX}}: made the two REXX programs more generic as far as specifying arguments (parameters).)
Line 3,212:
<lang rexx>/*REXX program finds/displays the first perfect square with N unique digits in base N.*/
numeric digits 40 /*ensure enough decimal digits for a #.*/
parse arg nLO HI . /*obtain optional argument from the CL.*/
if nLO=='' | n=="," then n= 16 then do; LO=2; HI=16; end /*not specified? Then use the default.*/
if LO==',' then LO=2 /* " " " " " " */
if HI=='' | HI=="," then HI=LO /* " " " " " " */
@start= 1023456789abcdefghijklmnopqrstuvwxyz /*contains the start # (up to base 36).*/
w= length(nHI) /* [↓] find the smallest square with */
do j=2LO to nHI; beg= left(@start, j) /* N unique digits in base N. */
do k=iSqrt( base(beg,10,j) ) until #==0 /*start each search from smallest sqrt.*/
$= base(k*k, j, 10) /*calculate square, convert to base J. */
Line 3,222 ⟶ 3,224:
#= verify(beg, $u) /*count differences between 2 numbers. */
end /*k*/
say 'base' right(j,w) " root=" right(base(k,j,10),max(5,nLO)) ' square=' $
end /*j*/
exit /*stick a fork in it, we're all done. */
Line 3,270 ⟶ 3,272:
<lang rexx>/*REXX program finds/displays the first perfect square with N unique digits in base N.*/
numeric digits 40 /*ensure enough decimal digits for a #.*/
parse arg nLO HI . /*obtain optional argument from the CL.*/
if nLO=='' | n=="," then n= 16 then do; LO=2; HI=16; end /*not specified? Then use the default.*/
if LO==',' then LO=2 /* " " " " " " */
if HI=='' | HI=="," then HI=LO /* " " " " " " */
@start= 1023456789abcdefghijklmnopqrstuvwxyz /*contains the start # (up to base 36).*/
call base /*initialize 2 arrays for BASE function*/
/* [↓] find the smallest square with */
do j=2LO to nHI; beg= left(@start, j) /* N unique digits in base N. */
do k=iSqrt( base(beg,10,j) ) until #==0 /*start each search from smallest sqrt.*/
$= base(k*k, j, 10) /*calculate square, convert to base J. */
#= verify(beg, $) /*count differences between 2 numbers. */
end /*k*/
say 'base' right(j, length(nHI) ) " root=" ,
lower( right( base(k, j, 10), max(5, nHI) ) ) ' square=' lower($)
end /*j*/
exit /*stick a fork in it, we're all done. */