Mathematica 9 is now available
Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Number-Theory :: All-Digit Perfect Squares

  • To: mathgroup at
  • Subject: [mg64264] Number-Theory :: All-Digit Perfect Squares
  • From: bd satish <bdsatish at>
  • Date: Wed, 8 Feb 2006 03:54:09 -0500 (EST)
  • Sender: owner-wri-mathgroup at

        Hi buddies,

                         I set out to write a code that generates nine-digit
perfect square numbers , with each of the digits 1,2,3,...9 occuring only once
in a given number. An example is 139854276  = 11826^2 . Obviuously , all
such numbers must lie in the interval [123456789 , 987654321] . Since
11111^2 < 123456789 and 31427^2 > 987654321 ,  all the square numbers must
have their square-roots
in the interval (11111,31427) .

              I need suggetions from you guys to help me improve the code or
to make it better or

                           The logic I used is this:

 (a).  Generate all the squares of integers in the range [11111,31427]

 (b).  Seperate the numbers into digits (using the command IntegerDigits[ ]

 (c).  Check , how many (or which and all)  numbers in this list  have each
of the digits 1,2,3,...8,9 exactly once.

 (d).  Collect all those lists and put them back as numbers (using the
command FromDigits[ ] )

           Here is the actual code:

 squares = IntegerDigits[Table[i ^ 2 , { i,11111,31427}]];
 sel = { } ; (* empty-list*)
       p = squares[[k]];
       logic =
                   MemberQ[p,7],MemberQ[p,8],MemberQ[p,9] ] ;

       If[TrueQ[logic] , sel = Append[sel,p]] ,

 The code does work perfectly, giving a list of 30 such  numbers.

 Will anyone help to to improve the code , if possible ?

 I would like to get rid of MemberQ[..] repeated so often.

  • Prev by Date: Re: Strange Syntax problem
  • Next by Date: Re: Solve problems
  • Previous by thread: Re: Batch Mode Return Code by WindowsDavid Bailey,
  • Next by thread: Re: Number-Theory :: All-Digit Perfect Squares