parent
d10eb5cc6c
commit
92455e38b3
@ -0,0 +1 @@
|
||||
.idea
|
@ -0,0 +1,146 @@
|
||||
addx 15
|
||||
addx -11
|
||||
addx 6
|
||||
addx -3
|
||||
addx 5
|
||||
addx -1
|
||||
addx -8
|
||||
addx 13
|
||||
addx 4
|
||||
noop
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx -35
|
||||
addx 1
|
||||
addx 24
|
||||
addx -19
|
||||
addx 1
|
||||
addx 16
|
||||
addx -11
|
||||
noop
|
||||
noop
|
||||
addx 21
|
||||
addx -15
|
||||
noop
|
||||
noop
|
||||
addx -3
|
||||
addx 9
|
||||
addx 1
|
||||
addx -3
|
||||
addx 8
|
||||
addx 1
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -36
|
||||
noop
|
||||
addx 1
|
||||
addx 7
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
addx 6
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
addx 7
|
||||
addx 1
|
||||
noop
|
||||
addx -13
|
||||
addx 13
|
||||
addx 7
|
||||
noop
|
||||
addx 1
|
||||
addx -33
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 8
|
||||
noop
|
||||
addx -1
|
||||
addx 2
|
||||
addx 1
|
||||
noop
|
||||
addx 17
|
||||
addx -9
|
||||
addx 1
|
||||
addx 1
|
||||
addx -3
|
||||
addx 11
|
||||
noop
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
addx -13
|
||||
addx -19
|
||||
addx 1
|
||||
addx 3
|
||||
addx 26
|
||||
addx -30
|
||||
addx 12
|
||||
addx -1
|
||||
addx 3
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -9
|
||||
addx 18
|
||||
addx 1
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
addx 9
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -1
|
||||
addx 2
|
||||
addx -37
|
||||
addx 1
|
||||
addx 3
|
||||
noop
|
||||
addx 15
|
||||
addx -21
|
||||
addx 22
|
||||
addx -6
|
||||
addx 1
|
||||
noop
|
||||
addx 2
|
||||
addx 1
|
||||
noop
|
||||
addx -10
|
||||
noop
|
||||
noop
|
||||
addx 20
|
||||
addx 1
|
||||
addx 2
|
||||
addx 2
|
||||
addx -6
|
||||
addx -11
|
||||
noop
|
||||
noop
|
||||
noop
|
@ -0,0 +1,6 @@
|
||||
noop
|
||||
addx 3
|
||||
addx -5
|
||||
noop
|
||||
noop
|
||||
noop
|
@ -0,0 +1,26 @@
|
||||
lines = open('input.txt', "r").read().splitlines()
|
||||
|
||||
cycle = 0
|
||||
x = 1
|
||||
signals = [20, 60, 100, 140, 180, 220]
|
||||
strengths = []
|
||||
for line in lines:
|
||||
cmd = line.split(" ")
|
||||
if len(signals) == 0:
|
||||
signals.append(9999999)
|
||||
elif cycle == signals[0]:
|
||||
strengths.append(x *cycle)
|
||||
signals.pop(0)
|
||||
elif cycle + 1 == signals[0]:
|
||||
strengths.append(x * (cycle+1))
|
||||
signals.pop(0)
|
||||
elif cycle + 2 == signals[0]:
|
||||
strengths.append(x * (cycle+2))
|
||||
signals.pop(0)
|
||||
if cmd[0] == "noop":
|
||||
cycle += 1
|
||||
else:
|
||||
cycle += 2
|
||||
x += int(cmd[1])
|
||||
print(sum(strengths))
|
||||
|
@ -0,0 +1,29 @@
|
||||
lines = open('input.txt', "r").read().splitlines()
|
||||
|
||||
cycle = 0
|
||||
x = 1
|
||||
end = [40, 80, 120, 160, 200, 240]
|
||||
registers = [999999 for y in range(240)]
|
||||
for line in lines:
|
||||
cmd = line.split(" ")
|
||||
registers[cycle] = x
|
||||
if cmd[0] == "noop":
|
||||
cycle += 1
|
||||
else:
|
||||
registers[cycle+1] = x
|
||||
cycle += 2
|
||||
x += int(cmd[1])
|
||||
|
||||
pixel_pos = 0
|
||||
screen = ""
|
||||
for r in range(len(registers)):
|
||||
if r in end:
|
||||
screen += "\n"
|
||||
pixel_pos = 0
|
||||
if pixel_pos in [registers[r]-1, registers[r], registers[r]+1]:
|
||||
screen += "#"
|
||||
else:
|
||||
screen += "."
|
||||
pixel_pos += 1
|
||||
|
||||
print(screen)
|
@ -0,0 +1,146 @@
|
||||
noop
|
||||
addx 5
|
||||
addx -2
|
||||
noop
|
||||
noop
|
||||
addx 7
|
||||
addx 15
|
||||
addx -14
|
||||
addx 2
|
||||
addx 7
|
||||
noop
|
||||
addx -2
|
||||
noop
|
||||
addx 3
|
||||
addx 4
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
addx 1
|
||||
addx 2
|
||||
addx 5
|
||||
addx -40
|
||||
noop
|
||||
addx 5
|
||||
addx 2
|
||||
addx 15
|
||||
noop
|
||||
addx -10
|
||||
addx 3
|
||||
noop
|
||||
addx 2
|
||||
addx -15
|
||||
addx 20
|
||||
addx -2
|
||||
addx 2
|
||||
addx 5
|
||||
addx 3
|
||||
addx -2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
addx 2
|
||||
addx 5
|
||||
addx -38
|
||||
addx 3
|
||||
noop
|
||||
addx 2
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
addx -2
|
||||
addx 5
|
||||
addx 2
|
||||
addx -2
|
||||
noop
|
||||
addx 7
|
||||
noop
|
||||
addx 10
|
||||
addx -5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -15
|
||||
addx 22
|
||||
addx 3
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
addx -37
|
||||
noop
|
||||
noop
|
||||
addx 13
|
||||
addx -10
|
||||
noop
|
||||
addx -5
|
||||
addx 10
|
||||
addx 5
|
||||
addx 2
|
||||
addx -6
|
||||
addx 11
|
||||
addx -2
|
||||
addx 2
|
||||
addx 5
|
||||
addx 3
|
||||
noop
|
||||
addx 3
|
||||
addx -2
|
||||
noop
|
||||
addx 6
|
||||
addx -22
|
||||
addx 23
|
||||
addx -38
|
||||
noop
|
||||
addx 7
|
||||
noop
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 9
|
||||
addx -8
|
||||
addx 2
|
||||
addx 7
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
addx -4
|
||||
addx 5
|
||||
addx 5
|
||||
addx 2
|
||||
addx -26
|
||||
addx 31
|
||||
noop
|
||||
addx 3
|
||||
noop
|
||||
addx -40
|
||||
addx 7
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
addx 4
|
||||
noop
|
||||
addx -1
|
||||
addx 5
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 5
|
||||
addx 1
|
||||
noop
|
||||
addx 4
|
||||
addx 3
|
||||
noop
|
||||
addx -24
|
||||
noop
|
@ -0,0 +1,8 @@
|
||||
R 4
|
||||
U 4
|
||||
L 3
|
||||
D 1
|
||||
R 4
|
||||
D 1
|
||||
L 5
|
||||
R 2
|
@ -0,0 +1,8 @@
|
||||
R 5
|
||||
U 8
|
||||
L 8
|
||||
D 3
|
||||
R 17
|
||||
D 10
|
||||
L 25
|
||||
U 20
|
@ -0,0 +1,64 @@
|
||||
lines = open("input.txt", "r").read().splitlines()
|
||||
|
||||
class Knots:
|
||||
def __init__(self):
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.pos = []
|
||||
|
||||
def visited(self):
|
||||
return len(set(self.pos))
|
||||
|
||||
t= Knots()
|
||||
h = Knots()
|
||||
|
||||
def move(h, t):
|
||||
if abs(h.x - t.x) <= 1 and abs(h.y - t.y) <= 1:
|
||||
pass
|
||||
elif abs(h.x - t.x) > 1 and abs(h.y - t.y) == 0:
|
||||
if h.x > t.x:
|
||||
t.x += 1
|
||||
else:
|
||||
t.x -= 1
|
||||
elif abs(h.x - t.x) == 0 and abs(h.y - t.y) > 1:
|
||||
if h.y > t.y:
|
||||
t.y += 1
|
||||
else:
|
||||
t.y -= 1
|
||||
else:
|
||||
if h.x > t.x and h.y > t.y :
|
||||
t.x += 1
|
||||
t.y += 1
|
||||
elif h.x > t.x and h.y < t.y:
|
||||
t.x += 1
|
||||
t.y -= 1
|
||||
elif h.x < t.x and h.y < t.y:
|
||||
t.x -= 1
|
||||
t.y -= 1
|
||||
else:
|
||||
t.x -= 1
|
||||
t.y += 1
|
||||
t.pos.append((t.x,t.y))
|
||||
|
||||
|
||||
t.pos.append((0,0))
|
||||
for line in lines:
|
||||
cmd = line.split(" ")
|
||||
if cmd[0] == "R":
|
||||
for i in range(int(cmd[1])):
|
||||
h.x = h.x + 1
|
||||
move(h, t)
|
||||
if cmd[0] == "L":
|
||||
for i in range(int(cmd[1])):
|
||||
h.x = h.x - 1
|
||||
move(h, t)
|
||||
if cmd[0] == "U":
|
||||
for i in range(int(cmd[1])):
|
||||
h.y = h.y + 1
|
||||
move(h, t)
|
||||
if cmd[0] == "D":
|
||||
for i in range(int(cmd[1])):
|
||||
h.y = h.y - 1
|
||||
move(h, t)
|
||||
|
||||
print(t.visited())
|
@ -0,0 +1,69 @@
|
||||
lines = open("input.txt", "r").read().splitlines()
|
||||
|
||||
class Knots:
|
||||
def __init__(self):
|
||||
self.x = 0
|
||||
self.y = 0
|
||||
self.pos = []
|
||||
|
||||
def visited(self):
|
||||
return len(set(self.pos))
|
||||
|
||||
k = []
|
||||
for i in range(10):
|
||||
k.append(Knots())
|
||||
k[i].pos.append((0,0))
|
||||
|
||||
def move(h, t):
|
||||
if abs(h.x - t.x) <= 1 and abs(h.y - t.y) <= 1:
|
||||
pass
|
||||
elif abs(h.x - t.x) > 1 and abs(h.y - t.y) == 0:
|
||||
if h.x > t.x:
|
||||
t.x += 1
|
||||
else:
|
||||
t.x -= 1
|
||||
elif abs(h.x - t.x) == 0 and abs(h.y - t.y) > 1:
|
||||
if h.y > t.y:
|
||||
t.y += 1
|
||||
else:
|
||||
t.y -= 1
|
||||
else:
|
||||
if h.x > t.x and h.y > t.y :
|
||||
t.x += 1
|
||||
t.y += 1
|
||||
elif h.x > t.x and h.y < t.y:
|
||||
t.x += 1
|
||||
t.y -= 1
|
||||
elif h.x < t.x and h.y < t.y:
|
||||
t.x -= 1
|
||||
t.y -= 1
|
||||
else:
|
||||
t.x -= 1
|
||||
t.y += 1
|
||||
t.pos.append((t.x,t.y))
|
||||
|
||||
|
||||
for line in lines:
|
||||
cmd = line.split(" ")
|
||||
if cmd[0] == "R":
|
||||
for _ in range(int(cmd[1])):
|
||||
k[0].x = k[0].x + 1
|
||||
for i in range(1, 10):
|
||||
move(k[i-1], k[i])
|
||||
if cmd[0] == "L":
|
||||
for _ in range(int(cmd[1])):
|
||||
k[0].x = k[0].x - 1
|
||||
for i in range(1, 10):
|
||||
move(k[i-1], k[i])
|
||||
if cmd[0] == "U":
|
||||
for _ in range(int(cmd[1])):
|
||||
k[0].y = k[0].y + 1
|
||||
for i in range(1, 10):
|
||||
move(k[i-1], k[i])
|
||||
if cmd[0] == "D":
|
||||
for _ in range(int(cmd[1])):
|
||||
k[0].y = k[0].y - 1
|
||||
for i in range(1, 10):
|
||||
move(k[i-1], k[i])
|
||||
|
||||
print(k[-1].visited())
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue