Four 4-digit perfect squares are arranged one above the other, in ascending order. No two digits within any one of these squares is the same. If you sum the digits of each of these four squares, each result is the same sum. Also, the sum of the digits of each column formed by placing these digits above one another is the same. There may or may not be repeated digits within a column.
What are the 4-digit squares?
The program opens with all 4 digit squares which have no repetion of digits as data.
It proceeds to compare squares with the same digital sum as well as comparing the sums of the 4 power positions.
Why Charlie specified ranking the squares in ascending order I have no idea but the concept greatly assisted in the writing of this program.
The program finds:
Squares Row Sums Column Sums
1764 3249 5184 9801 18 18
Copied from my spreadsheet:
Row
N N^2 Digits Sum
42 1764 1 7 6 4 18
57 3249 3 2 4 9 18
72 5184 5 1 8 4 18
99 9801 9 8 0 1 18
Col Sum 18 18 18 18
CLS
DATA 1024, 1089, 1296, 1369, 1764, 1849, 1936, 2304, 2401
DATA 2601, 2704, 2809, 2916, 3025, 3249, 3481, 3721, 4096
DATA 4356, 4761, 5041, 5184 ,5329, 5476, 6084, 6241, 6724
DATA 7056, 7396, 7569, 7921, 8649, 9025, 9216, 9604, 9801
DIM SHARED square(36)
OPEN "sqinsq3.txt" FOR OUTPUT AS #1
FOR a = 1 TO 36: READ square(a): NEXT
FOR a = 1 TO 33
FOR b = a + 1 TO 34
FOR c = b + 1 TO 35
FOR d = c + 1 TO 36
p = square(a)
q = square(b)
r = square(c)
s = square(d)
v1 = INT(p / 1000)
tmp = p - v1 * 1000
v2 = INT(tmp / 100)
tmp = tmp - v2 * 100
v3 = INT(tmp / 10)
tmp = tmp - v3 * 10
v4 = tmp
w1 = INT(q / 1000)
tmp = q - w1 * 1000
w2 = INT(tmp / 100)
tmp = tmp - w2 * 100
w3 = INT(tmp / 10)
tmp = tmp - w3 * 10
w4 = tmp
x1 = INT(r / 1000)
tmp = r - x1 * 1000
x2 = INT(tmp / 100)
tmp = tmp - x2 * 100
x3 = INT(tmp / 10)
tmp = tmp - x3 * 10
x4 = tmp
y1 = INT(s / 1000)
tmp = s - y1 * 1000
y2 = INT(tmp / 100)
tmp = tmp - y2 * 100
y3 = INT(tmp / 10)
tmp = tmp - y3 * 10
y4 = tmp
tot1 = v1 + w1 + x1 + y1
tot2 = v2 + w2 + x2 + y2
tot3 = v3 + w3 + x3 + y3
tot4 = v4 + w4 + x4 + y4
row1 = v1 + v2 + v3 + v4
row2 = w1 + w2 + w3 + w4
row3 = x1 + x2 + x3 + x4
row4 = y1 + y2 + y3 + y4
tot5 = 0: row5 = 0
IF (tot1 = tot2 AND tot2 = tot3 AND tot3 = tot4) THEN tot5 = 1
IF (row1 = row2 AND row2 = row3 AND row3 = row4) THEN row5 = 1
IF row5 = 1 AND tot5 = 1 THEN
PRINT p; q; r; s, tot1; row1
PRINT #1, p; q; r; s, tot1, row1
END IF
NEXT
NEXT
NEXT
NEXT
CLOSE 1
|
Posted by brianjn
on 2009-08-31 21:47:29 |