Skip to content

Commit b991bbc

Browse files
committed
dec 8
1 parent e3c2215 commit b991bbc

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

dec8/input.txt

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
..................................................
2+
................2.................................
3+
......6.........x.0..G............................
4+
..............x5......0..................S........
5+
.....0............................................
6+
..................................y..............e
7+
..........................G...............O.......
8+
.....................0........GO...............d..
9+
.........................8..........e.............
10+
.........6....................................e...
11+
......z6..5...N..x...................eY...........
12+
................6.........5..........Y.E..........
13+
.........X.....N....................E.a...S.....4.
14+
...........................N.2......d.............
15+
...s..................92.....a...................4
16+
............s....................GO........4......
17+
...........................................d.....S
18+
.....................X....N.......................
19+
.........A........................................
20+
.s.....................A....E.......a.........Y...
21+
.....g....s..................E.....Y..............
22+
.............o....................................
23+
...............................3...............O..
24+
.g.................F.3.y..........................
25+
.......F................y.....................d...
26+
..................................X...............
27+
..8....5............X..Z..........................
28+
..g.....8.....na..................................
29+
......................................3...........
30+
.............J.......x............S.Z.............
31+
..2J....h.A...............Z.......................
32+
......A.............................3.............
33+
............J.......n.............................
34+
.8......o....n...........Z........................
35+
..................o..............y................
36+
..F.........................D...............9H....
37+
.................................1.............9..
38+
..................................................
39+
.........h.....n......................f...........
40+
.h....................z..........j.........9......
41+
.......oF............................j............
42+
..........h......z...........7.....1.f............
43+
........................7.......1...H...j........f
44+
........................................f.........
45+
...........................7.......H..............
46+
................................H.................
47+
.............z...........D........................
48+
..............J....................Dj.............
49+
....................................D.............
50+
....................7.......1.....................

dec8/part1.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
lines = []
2+
with open("dec8/input.txt", "r") as file:
3+
for line in file.readlines():
4+
lines.append(line.strip())
5+
6+
7+
total = 0
8+
ants = {}
9+
for ind, line in enumerate(lines):
10+
for x, c in enumerate(line):
11+
if c != ".":
12+
ants.setdefault(c, [])
13+
ants[c].append((x, ind))
14+
pass
15+
found = []
16+
for ant in ants.keys():
17+
freq = ants[ant]
18+
for a in range(len(freq)):
19+
for b in range(len(freq)):
20+
if a != b:
21+
loc = (freq[a][0]* 2 - freq[b][0], freq[a][1]* 2 - freq[b][1])
22+
if 0 <= loc[0] < len(lines[0]) and 0 <= loc[1] < len(lines):
23+
if loc not in found:
24+
found.append(loc)
25+
total += 1
26+
print(ants)
27+
print(total)

dec8/part2.py

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
lines = []
2+
with open("dec8/input.txt", "r") as file:
3+
for line in file.readlines():
4+
lines.append(line.strip())
5+
6+
7+
total = 0
8+
ants = {}
9+
for ind, line in enumerate(lines):
10+
for x, c in enumerate(line):
11+
if c != ".":
12+
ants.setdefault(c, [])
13+
ants[c].append((x, ind))
14+
pass
15+
found = []
16+
for ant in ants.keys():
17+
freq = ants[ant]
18+
for a in range(len(freq)):
19+
for b in range(a + 1, len(freq)):
20+
if a != b:
21+
loca = freq[a]
22+
locb = freq[b]
23+
if loca[0] == locb[0]:
24+
pass
25+
else:
26+
slope = (loca[1]-locb[1])/(loca[0]-locb[0])
27+
for test in range(-50, 50):
28+
if int(round(slope * test, 8)) == round(slope * test, 8):
29+
loc = (loca[0] + test, loca[1] + round(slope * test, 8))
30+
if 0 <= loc[0] < len(lines[0]) and 0 <= loc[1] < len(lines):
31+
if loc not in found:
32+
found.append(loc)
33+
total += 1
34+
print(ants)
35+
print(total)

dec8/sample.txt

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

0 commit comments

Comments
 (0)