fantho69

magicsquare.py

Jul 14th, 2021 (edited)
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. def countoccurrances(n, d):
  2.     count = 0
  3.     while (n > 0):
  4.         if(n % 10 == d):
  5.             count = +=1
  6.         n = n // 10
  7.     return count
  8. def magicsquare(n):
  9.     for i in range(0,9):
  10.         if(countoccurrances(n*n,i)!=2):
  11.             return False
  12.     return True
  13. i=1
  14. for n in range(3164211346,9994386752):
  15.         if(magicsquare(n)):
  16.             string=str(i)+" "+str(n)+"  "+str(n*n)
  17.             print(string)
  18.             i+=1
Advertisement
Add Comment
Please, Sign In to add comment