File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 20
20
| [ 16] ( https://adventofcode.com/2020/day/16 ) | Ticket Translation| [ py] ( /day16/main.py ) , [ alt] ( /day16/alt.py ) |
21
21
| [ 17] ( https://adventofcode.com/2020/day/17 ) | Conway Cubes| [ py] ( /day17/main.py ) |
22
22
| [ 18] ( https://adventofcode.com/2020/day/18 ) | Operation Order| [ py] ( /day18/main.py ) |
23
- | [ 19] ( https://adventofcode.com/2020/day/19 ) | Monster Messages| [ py] ( /day19/main.py ) |
23
+ | [ 19] ( https://adventofcode.com/2020/day/19 ) | Monster Messages| [ py] ( /day19/main.py ) , [ alt ] ( /day19/alt.py ) |
24
24
| [ 20] ( https://adventofcode.com/2020/day/20 ) | -| -|
25
25
| [ 21] ( https://adventofcode.com/2020/day/21 ) | -| -|
26
26
| [ 22] ( https://adventofcode.com/2020/day/22 ) | -| -|
Original file line number Diff line number Diff line change
1
+ from lark import Lark , LarkError
2
+
3
+ def solve (rules , is_part1 ):
4
+ if not is_part1 :
5
+ rules = rules .replace ('8: 42' , '8: 42 | 42 8' )
6
+ rules = rules .replace ('11: 42 31' , '11: 42 31 | 42 11 31' )
7
+ rules = rules .translate (str .maketrans ('0123456789' , 'abcdefghij' ))
8
+ parser = Lark (rules , start = 'a' )
9
+
10
+ total = 0
11
+ for line in lines .splitlines ():
12
+ try :
13
+ parser .parse (line )
14
+ total += 1
15
+ except LarkError :
16
+ pass
17
+
18
+ return total
19
+
20
+ with open ("input.txt" ) as f :
21
+ rules , lines = [l .rstrip ("\n " ) for l in f .read ().split ("\n \n " )]
22
+
23
+ for is_part1 in [True , False ]:
24
+ print (solve (rules , is_part1 ))
You can’t perform that action at this time.
0 commit comments