Skip to content

Commit d8f46de

Browse files
committed
dec 6
1 parent 8a05d52 commit d8f46de

File tree

4 files changed

+243
-0
lines changed

4 files changed

+243
-0
lines changed

dec6/input.txt

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
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+
#...........#.............#...............................#..............................#...#.#........#.........................

dec6/part1.py

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
lines = []
2+
with open("dec6/sample.txt", "r") as file:
3+
for line in file.readlines():
4+
lines.append(line.strip())
5+
6+
7+
total = 0
8+
obstacles = []
9+
gx, gy = 0, 0
10+
for y, line in enumerate(lines):
11+
for x, c in enumerate(line):
12+
if c == "#":
13+
obstacles.append((x, y))
14+
if c == "^":
15+
gx, gy = x, y
16+
17+
pass
18+
print(obstacles)
19+
visited = []
20+
facing = 0
21+
dirs = [(0,-1), (1, 0), (0,1), (1,0)]
22+
while True:
23+
while (gx + dirs[facing][0], gy + dirs[facing][1]) in obstacles:
24+
facing = (facing + 1) % 4
25+
26+
gx += dirs[facing][0]
27+
gy += dirs[facing][1]
28+
print(gx, gy, facing)
29+
if gx < 0 or gx >= len(lines[0]) or gy < 0 or gy >= len(lines):
30+
break
31+
else:
32+
if (gx, gy) not in visited:
33+
visited.append((gx, gy))
34+
total += 1
35+
36+
print(total)

dec6/part2.py

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
lines = []
2+
with open("dec6/input.txt", "r") as file:
3+
for line in file.readlines():
4+
lines.append(line.strip())
5+
6+
7+
total = 0
8+
obstacles = []
9+
gx, gy = 0, 0
10+
for y, line in enumerate(lines):
11+
for x, c in enumerate(line):
12+
if c == "#":
13+
obstacles.append((x, y))
14+
if c == "^":
15+
gx, gy = x, y
16+
17+
pass
18+
print(obstacles)
19+
print(gx, gy)
20+
visited = [(gx, gy)]
21+
visdirs = [(gx, gy, 0)]
22+
boxes = []
23+
facing = 0
24+
dirs = [(0,-1), (1, 0), (0,1), (-1,0)]
25+
while True:
26+
turns = 0
27+
while (gx + dirs[facing][0], gy + dirs[facing][1]) in obstacles:
28+
facing = (facing + 1) % 4
29+
visdirs.append((gx, gy, facing))
30+
31+
gx += dirs[facing][0]
32+
gy += dirs[facing][1]
33+
if gx < 0 or gx >= len(lines[0]) or gy < 0 or gy >= len(lines):
34+
break
35+
else:
36+
visdirs.append((gx, gy, facing))
37+
38+
for index, path in enumerate(visdirs):
39+
gx = path[0]
40+
gy = path[1]
41+
facing = path[2]
42+
if (gx + dirs[path[2]][0], gy + dirs[path[2]][1]) not in boxes and\
43+
(gx + dirs[path[2]][0], gy + dirs[path[2]][1]) not in visited:
44+
obstacles.append((gx + dirs[path[2]][0], gy + dirs[path[2]][1]))
45+
testvisited = [(gx, gy, facing)]
46+
while True:
47+
while (gx + dirs[facing][0], gy + dirs[facing][1]) in obstacles:
48+
testvisited.append((gx, gy, facing))
49+
facing = (facing + 1) % 4
50+
51+
52+
gx += dirs[facing][0]
53+
gy += dirs[facing][1]
54+
55+
if gx < 0 or gx >= len(lines[0]) or gy < 0 or gy >= len(lines):
56+
break
57+
if (gx, gy, facing) in testvisited:
58+
total += 1
59+
boxes.append((path[0] + dirs[path[2]][0], path[1] + dirs[path[2]][1]))
60+
print(boxes[-1])
61+
break
62+
testvisited.append((gx, gy, facing))
63+
obstacles.pop(-1)
64+
visited.append((path[0], path[1]))
65+
if index % 100 == 0: print(index)
66+
67+
print(total)

dec6/sample.txt

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
....#.....
2+
.........#
3+
..........
4+
..#.......
5+
.......#..
6+
..........
7+
.#..^.....
8+
........#.
9+
#.........
10+
......#...

0 commit comments

Comments
 (0)