-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay21.py
More file actions
163 lines (159 loc) · 17.9 KB
/
Day21.py
File metadata and controls
163 lines (159 loc) · 17.9 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
puzzle_input = r'''...................................................................................................................................
.#.........#....#.....#...............#.................#..#...........#..........................#........#.......#..#.........#..
......##.#.....#......#....##....#......................#.#............#.........#......#.....................#................#...
....##.....##...........#.##......#.#....##.........#...................#......#.#....#...#..........#.........#........#......#...
......#..................##..#..........#..#.......#..#..#......................#.................#......#..#......#........#..#...
....#.........#..#..#.#......#.#.....#.#..#...........#.....................#......#......#........#....##...................#.....
..#......#..#........#.#.#.....#.......#......#...#.............#...............#...................#.........#....#.#...........#.
............#..................#...................#...........#..........................#............#.#.....#................#..
..#......#.....#..........#.........#............#.#.........#.....................#......#.................................##.....
...#.............................#.......#....................#....#.........................##........#...#................#......
.........#.......#...#............#......#............................................#.....#..........#...#......#......#.........
.....#.......#.................................................#..#.................#........#....##...............................
....................#.#........#..............#..............#............................#................#.......#..#.........#..
..........#.....#......#...........................................#...............#..##.....#.....#.#..............#..............
.#..............#...#..........#.............................#..#..#....#............#....................#......................#.
...###..............#.#.........#........................#...#..........................###...#.......#.#....................#.#...
......#...............#.#..#.........................#......................#........#.....#......#.................#......#.......
.............#................#............................#......#......#............#.....#....#....................#......##....
........................##.#...##..........#...........#.#...##........#...#...........#............##...#....................#..#.
.....#........#....#..#.................##................#....#....#.....#.................#.......#.#............................
...........#......................#.................#..#.#.....##...#.#....#..#...............#...#.....#...#..#..##......#.#....#.
...#...................#........................#......#................#..#.........................#..........#..................
........##..#.#................#..#.......................#.....#...........................#........#....#........................
...#............#.....#..........#.............##........#..#...#...........................#........#.##.....#..............#.....
..#.#.........#.......#.....#........#.........#.#...#.....#...........#..........#.............#...............###...#............
.........##........#...#....................#...#..#......#...........................#.............................#......#.......
.........#....#...........##................#...........##...#..#..#.............#................#.........................#....#.
.....#.....#...#.........#.......................#........#...#....#...#.........#.....#...............#...#.............#.........
..#....#..##.......#...#.........#........#......#.................#...#.......................................#......#............
.....................#....#..........................#..#...#......##....#.........#..#..............#..................#..........
.............#...##..##..............................#..#..#......#.........................................#..##...#..............
.......#.....#.........#...........................#........#...........#...........##...........................#.......#.........
..................#.#...................#......#..............#..............#.....#..#.#...................#.#...#..........#.....
.......................#...#.............#....#.##.###....##..........#......#..#.............#.........#......#..........#........
.#............#...........#..........#...#....#....#........................................##.........#..#........#.........#.....
....#...............................#......##............##.......#..............#......#....##...................#...#....#.......
.....#....#...##....#.#.....................#......#............................##.......#......#................#...............#.
..........#.#..#..#...........................#........#......#.................#...........................#..#......#...#........
...#.....#......................#...#...............#.##........#.###..........##..................#.........#.....................
..#..........#.......#.............#.........#....#...............#...#..#....#....#.#................................#.#...#......
.......#.......##....................#.##.......#...#.............#.............#.#...#......#..#...............#....#.............
..........#...................................#.......................##...#..............#.........#.....................#........
............##..#.........................#................................#...#..#...#..........#...#................#..#.........
..#.......##.#........................#..#....#....#..#.#.#........#...#........#................#.....#......................#.#..
..#...#.#....................#.......#.......#.#.##..#.....#..........#..........#.............#......#.#.........#................
....#....#.....#...........#.#.....#......#..................#..........#.......#................#................##...............
.#......#.................#...#..##.......#..#..........#...............#..........#....#.#...#......#.........................#...
..#.#.#...#...........#....#................##.............#..#..............#...#....#...##....#.........................#........
..#.....#...#..............#.......#..#...........................#...........#..........#..........#...#..............#......#.#..
..#...................#.........##............#....#..................#...............#..........#.......#.........................
......................................#........................#...#.......................#.......#........................#......
...#..#..#..........#.....#...........................................#.......#.............#......#.......#....#.........#........
..##.........................#.....#.................#..................##...##.....#.......#.........#...#.....#..............#...
..#.............#...##.#......................#....#.........##......#...........#..............#..#........#.....#.............##.
.....................#.#......................#..........#...##...........#............#.....#....................#..............#.
................#...#.......#............#.....#..#...##.#...#....#...#......#.#........#..........##........#.#....#..............
.............#...........#..............#..#.....#.........#...................................#.#.................................
.#..................#....#..........#.#..#........#.......................#..#.......#..................#.#.....................#..
................#.......#............................#............#..#.................#.#...#.....................................
............#.#............#........#.##........###..#........###......#.........................##.#.......#.......##.............
............#.#.......#.......#..##....#....................#.......................................#.....#.........#...#..........
...........##.....#..#...................#......................#.................#......#..#.......#...#...##.....................
......................................#...#....................#...#.................#........#......#.....#...#....##.............
.......................................#......................................#..............#......#........#.......#.............
.............###.............##......#........#..#.#....#...###.#..............#..........#.........#...........#..#......#........
.................................................................S.................................................................
......##...#.....#........#.......#.#....#....#....#................#..#..#...................#.....#................#.#...#.......
...............................#.....................#...##.......#........#.#.........#......................#....#...............
........................#.......#.........#..........#............#....#...##.........#...#.#............................#.........
........#..#..............##...........#....#.##..###.....................................#.##.....#................#..#...........
............#...#.............##..............................#.#........#...#...............#............#.##.....##...#..........
.................#......................................#..#..................#.....#............#.......#.......................#.
..#...................#.................#.................#..#....#...#..#...........#.#.#...#..#.........#........#...............
....#.........#....#...............##...............#.........#......................#...........#.............#...................
..............##.............#.....#..................#.....#.#.....#................#...#..........#.........#......#.............
..................#...#...###.........###..............#.............#................#...........#...#..#..#.....#................
.#..#...............#..#...........................##...#...#...#........#..........##...#....#........#...........................
...............................#............#....#..............#..#.....#............#.......#..#........................#........
.....##............#.............##...#..#....#.......#............#..........#.................#...........#.................#....
.....#............................#.....#...##.............#......#.....#..#.....##.......................#........................
..#.....#..........................#.#............#........#.#.......#...#...#.....#......................##................#...#..
.......#..............................#..................#.........................................#...#..................#.#..#...
......#....#.............................#...#.......#.....#......................#.#..........#..............................#....
.#..........................#........................#......#.........#......................#...#........#...........#...#........
.............#............#................#.......................................#..###..#.....#.....#.#...............#.......#.
.#........#..............................#........#...........#...........................#...........#...................#........
.......##.#...##...............#.#...........##.......#.#..............................#.....#.......#...........#.................
....#...###.#...............................#...........................#..................#..#.#...#............##.#..#....#......
....##....##...#..#...................##..#...#.#.......#...#.......................#......##....................#....#........#...
..............................#....#...#...#..................#.....#...................#....#.........................##...#......
...........#.#....#................................#.....#..#.................#..##......#..#......#.........#........#...#......#.
............................................#.#..........#...#.#....#.................#......#.#.#.#.........#........#......#.....
....#..............................##........#............#......................#.#..........#..........................#.....#...
.............#...##..#.............#........#.....#...#...............#..............#...........##..............................#.
................#...............................#.#..................#...........#.............##........#.......#....#..###.......
.#..........##.........................................#......#.#..#............................#...............##.#...#...........
.##.................##...................#.....................#..............#.........#........................#.....#...#...#...
.....................................................#..........#.#...........#.#..........#...............#.....#.......#...#.....
.#.............#.....##......#........#....#......................#.#.....#......#.......#......................#.....#...#......#.
........#...##.....#........#.........#.#..#............#...#.......................................#............#.................
......##..............#...###...........#............#.....................#............#.#...........................#............
..##.#......#......#....#......#.................#................#....................##..............#.......#.#.#....#..........
..#.......#.#.....#.##.....#................#.#.........#.....#.......#............................#..............#................
...#.#....#..#...........#......................................#.....#..................................#.......#...#..#..#.......
...#....#..#........#.......#...............#.........#..#..#.##.....#................#............................................
...........#...#.#.............##..............#.#.......#......#.........#.#......#..............#...................#............
...#.....#..##.....#..#.........#................#...#..#............#..##.#....#..............#..#...............#................
...#.#........##.........#..........#...........................#......#...#.......##...................#........#.#..##.........#.
.#.....#....................##.#................#..#.##................#........#..................................#..#.#...#......
.#..........#.....#....#..........#...................#........##............#.................#............#.....##...........#...
...........#...#.........#.#.......##..............#.........#..........##......#................#............##..##...............
.......#...#...#.....#....#.............##..............................................##...#................................#....
.#....##.....#...........#..........#..#............#.....##.......##...............................#.#...........#....#.........#.
.......#...#...............#........###....#..............................#............#..#...................#...#.........#......
......#...#.....#..........#....####.......#.#..................................................###.......#......#..#............#.
.#..#.......#..#.#....#....##......#........#.........##....................#......................................................
...........#.#.................................................#..........#............##..#..............#......#...##....#...#...
.#....................#......#.................................#.......................................#...#.......................
...................#.....................#...............#.....#.......................#...........#..#............#...............
...............#..#..#....#......#......#.........#............##..................................#.#..........##............#....
......#.......#.......#...#.............#.......#..#........#......#...#...........#.......#....#..............#..#..#.............
.....#......#.......##.#......................................#......##........#...#.............#...#..#......#............#......
.#........#..#.............#..#....###.............#...............#..........#...#......#......#...#....#.#.........#..........#..
........#....#....#.....#....#..#.................#.............................#............................#............#........
.....#...............#...........#.##...........................................#.#......#.....#.#..#....#..............##...#.....
..#..#....#..................................#.......#.#..........#........................#.........#.....................#.##....
...#....#.............#...#............#..........#.#..#...........................#.............#...#.......#................#.#..
..............#.....#......#.......#..........#....##..#................#.....#.....##.....#....#...........#......#...............
......#..#........................#.........#.......##....#.............................................##.....##.......#......#...
.....#..#.....#........................................#..............#............#...#...........................#........#......
...................................................................................................................................
'''
start_point = None
puzzle_map = list()
for row, line in enumerate(puzzle_input.splitlines()):
puzzle_map.append(line)
if start_point is None:
for col, value in enumerate(line):
if value == 'S':
start_point = [row,col]
break
row_count = len(puzzle_map)
col_count = len(puzzle_map[0])
# Let's search inside the diamond
count = 0
# Upper part
for r in range(start_point[0]-64,start_point[0]):
for c in range(start_point[1] - (r-1), start_point[1] + (r-1) + 1):
if( (r+c)%2 == 0 and puzzle_map[r][c] == '.'):
count += 1
# Lower part
for r in range(start_point[0],start_point[0]+65):
for c in range(start_point[1] - (129-r), start_point[1] + (130-r)):
if( (r+c)%2 == 0 and puzzle_map[r][c] == '.'):
count += 1
print(f"Part One: {count}")
# Observing the puzzle input, it is composed by 4 triangles at the borders
# and one diamond at the center. I'm pretty sure that we can use this geometry
# to infer a counting algorithm to be used on Part Two