All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    
perplexus dot info

Home > Numbers
Squares in a 4x4 Grid (Posted on 2023-07-21) Difficulty: 3 of 5
Leilani placed a digit in each of these 16 squares:
+------+------+------+------+
|      |      |      |      |      
+---- -+------+------+------+
|      |      |      |      |     
+------+------+------+------+
|      |      |      |      |     
+------+------+------+------+
|      |      |      |      |      
+------+------+------+------+

When she had finished, the grid had the following properties:

• No digit occured more than once in any row.
• The sum of the four digits in each row was the same.
• The sum of the four digits in each column was the same.
• Each row formed a different four-digit perfect square.

Complete the 4x4 square grid given above.

Note: Adapted from Enigma #1553 which appeared in 'New Scientist' in 2009.

See The Solution Submitted by K Sengupta    
Rating: 5.0000 (1 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Solution Solution | Comment 1 of 6
Some analysis shows that the only sets of 4 digit squares with no repeat digits such that 4 or more share the same sod are:
 18: [1089, 1296, 1764, 2916, 3249, 4356, 4761, 5184, 6084, 7056, 9216, 9801]
 19: [1369, 1936, 2809, 4096, 5329, 6724, 7921, 9604]
(first step was to make dictionary I called samesod)

From the sod() = 18 group, the only set of 4 which has different digits in each column (condition 3) is:
[Edit, correction: the only set of 4 which have the same sum of digits for each column]
(1764, 3249, 5184, 9801)
                                           
From the sod() = 19 group, no subset of 4 met condition 3.
Solution (with the rows in any order):
1764
3249
5184
9801

 -----------------
Dictionary "samesod" printed out
{7: [1024, 2401],
 18: [1089, 1296, 1764, 2916, 3249, 4356, 4761, 5184, 6084, 7056, 9216, 9801],
 19: [1369, 1936, 2809, 4096, 5329, 6724, 7921, 9604],
 22: [1849, 5476],
 9: [2304, 2601],
 13: [2704, 3721, 6241],
 10: [3025, 5041],
 16: [3481, 9025],
 25: [7396],
 27: [7569, 8649]}
The results for 18 and 19 'hardwired' into the program for the next step

 ---------  code  --------
def sod(n):
    """ Input an integer.  Returns the Sum of the Digits  """
    aList = list(str(n))
    ans = 0
    for c in aList:
        ans = ans + int(c)
    return ans

squares =  [i**2 for i in range(32,100) if len(set(str(i**2))) == 4]
samesod = {}
for s in squares:
    sods = sod(s)
    if sods not in samesod:
        samesod[sods] = [s]
    else:
        samesod[sods].append(s)

sod18 = [1089, 1296, 1764, 2916, 3249, 4356, 4761, 5184, 6084, 7056, 9216, 9801]
sod19 = [1369, 1936, 2809, 4096, 5329, 6724, 7921, 9604]

grids = []
from itertools import combinations
for c in combinations(sod18,4):
#for c in combinations(sod19,4):  #run either 18 or 19
    grid = [[d for d in str(c[i])]  for i in range(4)]
    reject = False
    flip = [[grid[j][i] for j in range(4) ]for i in range(4)]
    columnsods = [ sod( int(''.join(f)) )  for f in flip]
    if len(set(columnsods)) != 1:
        reject = True
    if reject:
        continue
    grids.append(c)

print(grids)

Edited on July 21, 2023, 9:48 am

Edited on July 21, 2023, 11:05 am
  Posted by Larry on 2023-07-21 09:46:04

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (3)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2024 by Animus Pactum Consulting. All rights reserved. Privacy Information