This week's book giveaway is in the Android forum. We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line! See this thread for details.

This was appeared in last month in one of regional newspaper(www.esakal.com). There is a four digit number in the form xxyy where x and y are different integers from 0 to 9.This number xxyy is a perfect square.Without using trial and error, find this number.

Cap, Do you mean the product (x*x*y*y) is a perfect square or the numbers strung up together xxyy is a perfect square ? regards

Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1888

posted

0

xxyy is a perfect square.(for e.g.if x=4 y=1, number is 4411)

HS Thomas
Ranch Hand

Joined: May 15, 2002
Posts: 3404

posted

0

A perfect square is a square number . Simply, 1, 4, 9, 16, 25, 36, 49 .....

If you consider the area of a square , I think you can determine the two numbers which add to a perfect square. a^2 = x^2 + y^2 where x and y are not the sides. Capablanca , are you sure it's xxyy and not x^2 + y^2 ? (Just checking before the sum diappears down a black hole.) regards [ September 30, 2003: Message edited by: HS Thomas ]

Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1888

posted

0

Yes,Number is in the form xxyy where x and y are integers which are not equal.(I found the method but it requires few trials). [ September 30, 2003: Message edited by: Capablanca Kepler ]

Originally posted by Capablanca Kepler: xxyy is a perfect square.(for e.g.if x=4 y=1, number is 4411)

Well, there isn't any! Okay, I cheated , but I was desperate, and still I couldn't find a perfect square between 1000 and 9999 matching above conditon. There's only one perfect square that follows this pattern, its 7744 and its squareroot is not 74, but its 88!!

Ummm, that's the answer, Ashok. What condition does it fail to meet? Without "cheating", I was able to establish that the number could be represented as (121*z*z), where z is an integer such that 4 <= z <= 9. However the only way I found to proceed further was by "trial and error" of the six possible values of z - plug them in to the formula, and see which results in a number of the form xxyy. Which is pretty easy really, but technically "cheating". So now I'm wondering if it's really even possible to find the solution without using any "trial and error". Anyone got a better solution?

"I'm not back." - Bill Harding, Twister

Ashok Mash
Ranch Hand

Joined: Oct 13, 2000
Posts: 1936

posted

0

Originally posted by Ashok Mash: 7744 and its squareroot is not 74, but its 88!!

Originally posted by Capablanca Kepler: xxyy is a perfect square.(for e.g.if x=4 y=1, number is 4411)

My understanding of the actual question was in lines of the above - that is if that perfectsquare is 7744, according to Capablanca, the root should be xy of xxyy, that is 74. And its not! 7744 is perfect square of 88. In other words, (xy)*(xy) (where xy is a integer between 10 and 99) should be equal to xxyy. We have xxyy, which is 7744, but its not square of 74, and hence doesnt meet his criteria! Well, I guess the question was wrong! [ September 30, 2003: Message edited by: Ashok Mash ]

Arjun Shastry
Ranch Hand

Joined: Mar 13, 2003
Posts: 1888

posted

0

Where did I say that square root follows the pattern xy?Number is in the form xxyy and it is perfect square.Thats the ONLY condition.Answer is 7744 as you obtained.Any number in this form xxyy is divisible by 11 and hence suqareroot should also contain 11.But there are still some trials.Number xxyy can be written as 1100x+11y = 121(10x+y - (10(x+y))/11) that means x+y must be divisible by 11.so possible combinations are 2+9,3+8,4+7,5+6 [ September 30, 2003: Message edited by: Capablanca Kepler ] [ October 01, 2003: Message edited by: Capablanca Kepler ]

Ashok Mash
Ranch Hand

Joined: Oct 13, 2000
Posts: 1936

posted

0

Originally posted by Capablanca Kepler: Originally posted by Capablanca Kepler: xxyy is a perfect square.(for e.g.if x=4 y=1, number is 4411)

Well, I guess I misunderstood the question! But with out the bit that I was looking for (xxyy, x & y patter match), its really easy anyway!

Here is the code. public static void perfectSquare() { int x = 0; int y = 0; String number = null; double sqrt = 0.00; int iNumber = 0; for (x = 1; x < 10; x++) { for (y = 1; y < 10; y++) { if (x != y) { number = "" + x + x + y + y; sqrt = Math.sqrt(Double.parseDouble(number)); iNumber = (int) sqrt; if (sqrt == iNumber) { System.out.println(number); } } } } } Vijay [ October 07, 2003: Message edited by: Vijay Rathore ]

SCJP, SCJD, SCWCD1.4, IBM486, IBM484, IBM 483, IBM 287, IBM141, IBM Certified Enterprise Developer - WebSphere Studio, V5.0
Author of IBM 287 Simulator Exam