Can do better without two loops :-|

latticePoints = 0

radius = 3.2

mod = int(radius) + 1

def isInCircle(x, y):

return x*x + y*y <= radius*radius

def calc(x, y):

global latticePoints

if x == 0 and y == 0:

latticePoints = latticePoints + 1

print((x, y))

elif x == 0 and y != 0:

latticePoints = latticePoints + 2

print((x, y),(x, -y))

elif x != 0 and y == 0:

latticePoints = latticePoints + 2

print((x, y),(-x, y))

else :

latticePoints = latticePoints + 4

print((x, y), (-x, -y), (x, -y), (-x, y))

for i in range(mod) :

for j in range(mod) :

if(isInCircle(i,j)):

calc(i,j)

print(latticePoints)

radius = 3.2

mod = int(radius) + 1

def isInCircle(x, y):

return x*x + y*y <= radius*radius

def calc(x, y):

global latticePoints

if x == 0 and y == 0:

latticePoints = latticePoints + 1

print((x, y))

elif x == 0 and y != 0:

latticePoints = latticePoints + 2

print((x, y),(x, -y))

elif x != 0 and y == 0:

latticePoints = latticePoints + 2

print((x, y),(-x, y))

else :

latticePoints = latticePoints + 4

print((x, y), (-x, -y), (x, -y), (-x, y))

for i in range(mod) :

for j in range(mod) :

if(isInCircle(i,j)):

calc(i,j)

print(latticePoints)

## 0 comments:

## Post a Comment