Compare commits

..

No commits in common. "a3e4290ccd2923a201d1347bc13bbe92ab4f4a21" and "383ff93502c487210e245b06535fd6e991bdb3d5" have entirely different histories.

4 changed files with 12 additions and 2056 deletions

View File

@ -6,30 +6,36 @@ scores = []
for ii in range(len(data)):
for jj in range(len(data[ii])):
top = data[ii][jj]
h = -1
a = 0
i = ii
for j in range(jj+1, len(data[ii])):
a += 1
if data[i][j] >= top:
h = data[ii][j]
if h >= top:
break
b = 0
h = -1
for j in reversed(range(0, jj)):
b += 1
if data[i][j] >= top:
h = data[ii][j]
if h >= top:
break
j = jj
c = 0
h = -1
for i in range(ii+1, len(data)):
c += 1
if data[i][j] >= top:
h = data[i][jj]
if h >= top:
break
d = 0
h = -1
for i in reversed(range(0, ii)):
d += 1
if data[i][j] >= top:
h = data[i][jj]
if h >= top:
break
print(ii,jj,a,b,c,d)

View File

@ -1,42 +0,0 @@
def go(p, dir):
x,y = p
if dir == "U": y += 1
elif dir == "D": y -= 1
elif dir == "L": x -= 1
elif dir == "R": x += 1
return x,y
def follow(h, t):
if abs(h[0] - t[0]) > 1 or abs(h[1] - t[1]) > 1:
x,y = t
x += sgn(h[0] - t[0])
y += sgn(h[1] - t[1])
t = x,y
return t
def sgn(x):
return (x > 0) - (x < 0)
def solve(n):
R = [(0,0)]*n
visited = set([R[-1]])
for line in open("input"):
dir, count = line.split()
for _ in range(int(count)):
R[0] = go(R[0], dir)
for i in range(1, len(R)):
t = follow(R[i-1], R[i])
if t == R[i]:
# optimization: if a knot doesn't move,
# none of the knots after it will either
break
R[i] = t
visited.add(R[-1])
#print(R)
return len(visited)
A1 = solve(2)
print(A1)
A2 = solve(10)
print(A2)

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +0,0 @@
R 4
U 4
L 3
D 1
R 4
D 1
L 5
R 2