File tree 5 files changed +86
-2
lines changed
5 files changed +86
-2
lines changed Original file line number Diff line number Diff line change 42
42
m = grid [i - width + 1 ] + grid [i + width - 1 ]
43
43
n += (m in ["MS" , "SM" ]) and l in ["MS" , "SM" ]
44
44
45
- print (n )
45
+ print (n )
46
+
47
+
48
+ print ("took %s seconds" % (time .time () - start_time ))
Original file line number Diff line number Diff line change 69
69
70
70
71
71
72
- print (n )
72
+ print (n )
73
+
74
+
75
+ print ("took %s seconds" % (time .time () - start_time ))
Original file line number Diff line number Diff line change
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 ))
You can’t perform that action at this time.
0 commit comments