Add testing script.py

This commit is contained in:
Dominic Zimmer 2020-07-09 10:14:48 +02:00
parent e84d807957
commit cfb3074158

View File

@ -14,8 +14,10 @@ def unpairZ(z):
lookup = [-10, 4, 1, 3, 0, 2] lookup = [-10, 4, 1, 3, 0, 2]
def isDiggingSpot(x, y): def isDiggingSpot(x, y):
val = lookup[(y % 5) + 1] x, y = int(x), int(y)
return (x % 5) == val val = lookup[(((y % 5)+5)%5) + 1]
out = ((x % 5)+ 5) % 5 == val
return out
global offset global offset
offset = 10 offset = 10
@ -30,4 +32,33 @@ def ithSpot(i):
else: else:
i = i - 1 i = i - 1
j = j + 1 j = j + 1
def adjustToQuadrant(i, x, z):
if i % 4 == 0:
return x, z
elif i % 4 == 1:
return -z-1, x
elif i % 4 == 2:
return z, -x-1
elif i % 4 == 3:
return -z-1, -x-1
def iTo2Dcoords(j):
i = j // 4
quadrantI = j % 4 # 0-3 quadrant
counter = 0 # number of digging spots found
j = 0 # enumerate 2D plane
while True:
x, z = int(unpairX(j)), int(unpairZ(j)) # coords in first quadrant
x, z = adjustToQuadrant(quadrantI, x, z) # map coords correctly into other quadrants
if isDiggingSpot(x, z):
if counter == i:
return (x,z)
break
counter += 1
j += 1
print(iTo2Dcoords(3))
# for i in range(10):
# print(iTo2Dcoords(i))