-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay17.py
88 lines (80 loc) · 2.7 KB
/
Day17.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
def parse():
with open("Day17input.txt", "r") as file:
output = []
for line in file:
for char in line:
if char in ["<", ">"]:
output.append(char)
return output
def get_rock_shape(rock_type):
shape = []
if rock_type == "_":
shape = [[".", ".", "#", "#", "#", "#", "."]]
elif rock_type == "+":
shape = [[".", ".", ".", "#", ".", ".", "."],
[".", ".", "#", "#", "#", ".", "."],
[".", ".", ".", "#", ".", ".", "."]
]
elif rock_type == "L":
shape = [[".", ".", ".", ".", "#", ".", "."],
[".", ".", ".", ".", "#", ".", "."],
[".", ".", "#", "#", "#", ".", "."]
]
elif rock_type == "l": #Small "L"
shape = [[".", ".", "#", ".", ".", ".", "."],
[".", ".", "#", ".", ".", ".", "."],
[".", ".", "#", ".", ".", ".", "."],
[".", ".", "#", ".", ".", ".", "."]
]
elif rock_type == "#":
shape = [[".", ".", "#", "#", ".", ".", "."],
[".", ".", "#", "#", ".", ".", "."]
]
return shape
def push_rock(rock, wind_direction):
if wind_direction == ">":
space = True
for row in rock:
if row[-1] == "#":
space = False
if space:
for row in rock:
length = len(row)
for i in range(len(row) - 1):
row[length - i] = row[length - i - 1]
elif wind_direction == "<":
shace = True
for row in rock:
if row[0] == "#":
space = False
if space:
for row in rock:
for i in range(len(row) - 1):
rock[i] = rock[i + 1]
def space_to_move_rock(rock, wind_blow, board):
height_rock = len(rock)
for i in range(
def collusion(rock, board, height):
pass
def part1(winds, n_rocks):
rock_types = ["_", "+", "L", "l", "#"] # The 4th rock is lowercase "L"
board = ["#"] * 7
j = 0
for ith_rock in range(n_rocks):
current_rock = rock_types[ith_rock % len(rock_types)]
rock = get_rock_shape(current_rock)
touch = False
height = -3
while not touch:
wind_blow = winds[j % len(winds)]
j += 1
if height >= 0:
space = space_to_move_rock(rock, wind_blow, board)
if space:
push_rock(rock, wind_blow)
collude = collusion(rock, board, height)
height += 1
if collude:
touch = True
winds = parse()
print(part1(winds, 10))