Moved 2022 to own dir

This commit is contained in:
2023-11-30 19:20:34 +02:00
parent e700358bda
commit 6bd452a4ec
16 changed files with 0 additions and 0 deletions

53
2022/10/j.py Normal file
View File

@@ -0,0 +1,53 @@
import os
import sys
input = open(os.path.dirname(__file__) +
"/input.txt", "r").readlines()
cost = {
'noop': 1,
'addx': 2
}
H = 6
W = 40
screen = [[False for i in range(W)] for j in range(H)]
cycle = 1
X = 1
strs = []
line = 1
for l in input:
cmd = l.split()
for i in range(cost[cmd[0]]):
pos = cycle % 40 - 1
# p1
if ((cycle+20) % 40) == 0:
strenth = cycle*X
strs.append(strenth)
# p2
if cycle % 40 == 0:
line += 1
if (pos == X-1 or pos == X or pos == X+1):
screen[line-1][pos] = True
cycle += 1
if cmd[0] == 'addx':
X += int(cmd[1])
# p1
print(sum(strs))
# p2
for y in range(H):
for x in range(W):
if (screen[y][x]):
print("#", end="")
else:
print(".", end="")
print()