How to resolve the algorithm First perfect square in base n with n unique digits step by step in the Factor 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 Factor 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 Factor programming language
Source code in the factor programming language
USING: assocs formatting fry kernel math math.functions
math.parser math.ranges math.statistics sequences ;
IN: rosetta-code.A260182
: pandigital? ( n base -- ? )
[ >base histogram assoc-size ] keep >= ;
! Return the smallest decimal integer square root whose squared
! digit length in base n is at least n.
: search-start ( base -- n ) dup 1 - ^ sqrt ceiling >integer ;
: find-root ( base -- n )
[ search-start ] [ ] bi
'[ dup sq _ pandigital? ] [ 1 + ] until ;
: show-base ( base -- )
dup find-root dup sq pick [ >base ] curry bi@
"Base %2d: %8s squared = %s\n" printf ;
: main ( -- ) 2 16 [a,b] [ show-base ] each ;
MAIN: main
You may also check:How to resolve the algorithm Percolation/Mean cluster density step by step in the Nim programming language
You may also check:How to resolve the algorithm Fibonacci sequence step by step in the LabVIEW programming language
You may also check:How to resolve the algorithm Singly-linked list/Element definition step by step in the Sidef programming language
You may also check:How to resolve the algorithm Window management step by step in the Python programming language
You may also check:How to resolve the algorithm Substitution cipher step by step in the Ada programming language