Skip to content

Commit 3560fc5

Browse files
committed
day 6
1 parent 59e54e1 commit 3560fc5

File tree

5 files changed

+86
-2
lines changed

5 files changed

+86
-2
lines changed

4/4.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,7 @@
4242
m = grid[i-width+1] + grid[i+width-1]
4343
n += (m in ["MS", "SM"]) and l in ["MS", "SM"]
4444

45-
print(n)
45+
print(n)
46+
47+
48+
print("took %s seconds" % (time.time() - start_time))

5/5.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,7 @@
6969

7070

7171

72-
print(n)
72+
print(n)
73+
74+
75+
print("took %s seconds" % (time.time() - start_time))

6/6.py

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# allow importing from parent folder
2+
import sys
3+
sys.path.append('../AOC-2024')
4+
5+
from utils.readfile import *
6+
from utils.calc import *
7+
from utils.graph import *
8+
from utils.util import *
9+
import re
10+
import math
11+
import copy
12+
import numpy as np
13+
from itertools import combinations, permutations, product
14+
import re
15+
import time
16+
17+
18+
grid = read_raw_text("6")
19+
width = grid.index("\n")+1
20+
21+
22+
start_time = time.time()
23+
24+
25+
26+
27+
print("PART 1:")
28+
29+
uniq = set()
30+
pos = grid.index("^")
31+
dirs = [-width, 1, width, -1]
32+
dir = 0
33+
34+
fail = 0
35+
while grid[pos] != "\n" and fail == 0:
36+
try:
37+
uniq |= {pos}
38+
if grid[pos+dirs[dir]] == "#":
39+
dir = (dir+1)%4
40+
else:
41+
pos += dirs[dir]
42+
except: fail = 1
43+
44+
45+
46+
47+
print(len(uniq))
48+
49+
50+
51+
print("PART 2:")
52+
53+
n = 0
54+
55+
for check in uniq:
56+
seen = set()
57+
pos = grid.index("^")
58+
dir = 0
59+
60+
while 1:
61+
if (pos, dir) in seen:
62+
n += 1
63+
break
64+
if not (0 <= pos < len(grid)) or grid[pos] == "\n":
65+
break
66+
if grid[pos] == "#" or pos==check:
67+
pos -= dirs[dir]
68+
dir = (dir+1)%4
69+
else:
70+
seen |= {(pos, dir)}
71+
pos += dirs[dir]
72+
73+
74+
75+
print(n)
76+
77+
78+
print("took %s seconds" % (time.time() - start_time))

6/6.rock

Whitespace-only changes.

6/6_lyrics.rock

Whitespace-only changes.

0 commit comments

Comments
 (0)