We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
my solution is based on the fact of 9 distinct digits with total sum of 45 (1-9) meaning sum of each row/colum being 15.
This solution fails few tests on summission without any ability to debug. Also the expected output is incorrect coming from the HackerRank in my opinion. So what's going on here?
def formingMagicSquare(s):
r1=sum(s[0])
r2=sum(s[1])
r3=sum(s[2])
column_sums=[sum (column) for column in zip(*s)]
c1=column_sums[0]
c2=column_sums[1]
c3=column_sums[2]
row_correction = abs(r1-15)+abs(r2-15)+abs(r3-15)
column_correction = abs(c1-15)+abs(c2-15)+abs(c3-15)
#print(s)
#print(f"row_correction:{row_correction} && column_correction:{column_correction}")
if row_correction>=column_correction:
return row_correction
else:
return column_correction
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Forming a Magic Square
You are viewing a single comment's thread. Return to all comments →
my solution is based on the fact of 9 distinct digits with total sum of 45 (1-9) meaning sum of each row/colum being 15.
This solution fails few tests on summission without any ability to debug. Also the expected output is incorrect coming from the HackerRank in my opinion. So what's going on here?
def formingMagicSquare(s):