-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_10.py
68 lines (55 loc) · 1.55 KB
/
day_10.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import aoc_helper
import re
from aoc_helper import (
iter,
range,
decode_text,
)
raw = aoc_helper.fetch(10, 2022)
#raw = open("sample_input.txt").read()
def parse_raw():
global raw
raw = re.sub(r'addx (-?\d+)', r'addx 0\naddx \1',
raw).replace("noop", "noop 0")
return [(i.strip().split()[0], int(i.strip().split()[1])) for i in raw.splitlines()]
data = iter(parse_raw())
def part_one():
cycle = 1
i = data.next()
X = 1
s = 0
while cycle <= 220:
if cycle in [20 + 40*k for k in range(6)]:s += cycle * X
cycle += 1
X += i[1]
i = data.next()
print(s)
return s
def part_two():
cycle = 1
i = data.next()
monitor = ''
X = 1
while cycle <= 240:
if ((cycle-1) % 40 in [X-1, X, X+1]):
# Different Printintg Modes
#monitor += '⬜🟨🟦'[[X-1,X,X+1].index((cycle-1)%40)]
monitor += '🔲'
#monitor += '⬜🟨🟦'[((cycle-1)//40) % 3]
#monitor += '#'
else:
monitor += '⬛'
#monitor += ' '
if (cycle % 40 == 0):
monitor += '\n'
cycle += 1
X += i[1]
try:
i = data.next()
except StopIteration:
i = ('noop', 0)
print(monitor)
return decode_text(list(map(lambda x : [(True if i == '🔲' else False) for i in x],monitor.splitlines())))
aoc_helper.lazy_submit(day=10, year=2022, solution=part_one)
#print(part_two())
aoc_helper.lazy_submit(day=10, year=2022, solution=part_two)