File tree 3 files changed +88
-0
lines changed
3 files changed +88
-0
lines changed Original file line number Diff line number Diff line change
1
+ initial state: #..#.#..##......###...###
2
+
3
+ ...## => #
4
+ ..#.. => #
5
+ .#... => #
6
+ .#.#. => #
7
+ .#.## => #
8
+ .##.. => #
9
+ .#### => #
10
+ #.#.# => #
11
+ #.### => #
12
+ ##.#. => #
13
+ ##.## => #
14
+ ###.. => #
15
+ ###.# => #
16
+ ####. => #
Original file line number Diff line number Diff line change
1
+ initial state: ##.#..#.#..#.####.#########.#...#.#.#......##.#.#...##.....#...#...#.##.#...##...#.####.##..#.#..#.
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
+ #..## => #
Original file line number Diff line number Diff line change
1
+ def find_match (rule , pots ):
2
+ for i in range (len (pots )- 5 ):
3
+ if pots [i :i + 5 ] == rule :
4
+ return i + 2
5
+ return None
6
+
7
+ from collections import defaultdict
8
+
9
+ def getsum (pots , first ):
10
+ s = 0
11
+ for i ,c in enumerate (pots ):
12
+ if c == "#" :
13
+ s += i - first
14
+ return s
15
+
16
+ with open ('input' ) as f :
17
+ lines = f .read ().splitlines ()
18
+ pots = lines [0 ].split (": " )[1 ]
19
+ pots = "." * 20000 + pots + "." * 20000
20
+ first = 0
21
+ for i ,c in enumerate (pots ):
22
+ if c == "#" :
23
+ first = i
24
+ break
25
+
26
+ rules = defaultdict (lambda : "." )
27
+ for rule in lines [2 :]:
28
+ condition , replacement = rule .split (" => " )
29
+ rules [condition ] = replacement
30
+
31
+ for g in range (200 ):
32
+ newpots = list (pots )
33
+ for i in range (2 , len (pots )- 2 ):
34
+ newpots [i ] = rules [pots [i - 2 :i + 3 ]]
35
+ pots = "" .join (newpots )
36
+ s = getsum (pots , first )
37
+
38
+ print ((50000000000 - 200 )* 87 + s )
You can’t perform that action at this time.
0 commit comments