This commit is contained in:
parent
0fa4605d49
commit
b6cd2b371f
1 changed files with 36 additions and 0 deletions
36
2022/10/10_2.py
Normal file
36
2022/10/10_2.py
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# 2022 - Advent Of Code 10 part 2
|
||||||
|
|
||||||
|
|
||||||
|
# file = 'input_example.txt'
|
||||||
|
# file = 'input_example2.txt'
|
||||||
|
file = 'input.txt'
|
||||||
|
|
||||||
|
cycle = 1
|
||||||
|
regX = 1
|
||||||
|
|
||||||
|
|
||||||
|
def check_cycle(c, r):
|
||||||
|
if c % 40 >= r - 1 and c % 40 <= r + 1:
|
||||||
|
print('#', end='')
|
||||||
|
else:
|
||||||
|
print('.', end='')
|
||||||
|
if c % 40 == 0:
|
||||||
|
print()
|
||||||
|
|
||||||
|
|
||||||
|
with open(file, encoding="utf-8") as f:
|
||||||
|
for line in f.readlines():
|
||||||
|
if line.startswith('noop'):
|
||||||
|
check_cycle(cycle, regX)
|
||||||
|
cycle += 1
|
||||||
|
else:
|
||||||
|
value = int(line.strip().split(' ')[1])
|
||||||
|
check_cycle(cycle, regX)
|
||||||
|
cycle += 1
|
||||||
|
|
||||||
|
regX += value
|
||||||
|
check_cycle(cycle, regX)
|
||||||
|
cycle += 1
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue