I am trying to determine the number of lattice points in a circle, i.e. basically I'm trying to find the number of pairs (m, n) such that m ^ 2 + n ^ 2 <= r ^ 2, where m and n are integers. I used the code below for this, but I get the wrong answer for r = 12, which should be 441 according to this , and I get 121, and I was wondering where I could be wrong:
def latticepoints(N):
num = 0
for m in range(0, int(N), 1):
for n in range(0, int(N), 1):
if (m**2 + n**2) <= N**2:
num = num + 1
return number
print(latticepoints(12))
Edit
Just decided. Just need to change the loops to:
for m in range(-int(N), int(N)+1, 1):
for n in range(-int(N), int(N)+1, 1):
thanks
source
share