-
Notifications
You must be signed in to change notification settings - Fork 0
/
part_b.py
executable file
·47 lines (38 loc) · 1.15 KB
/
part_b.py
1
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
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
import json
from aox.challenge import Debugger
from utils import BaseChallenge
from . import part_a
class Challenge(BaseChallenge):
def solve(self, _input, debugger: Debugger):
"""
>>> Challenge().default_solve()
2074
"""
return LiteralSetExtended.from_literals_text(_input)\
.encode()\
.get_total_net_length()
class LiteralSetExtended(part_a.LiteralSet['LiteralExtended']):
def encode(self) -> 'LiteralSetExtended':
"""
>>> LiteralSetExtended.from_literals_text(
... '""\\n'
... '"abc"\\n'
... '"aaa\\\\"aaa"\\n'
... '"\\\\x27"\\n'
... ).encode().get_total_net_length()
19
"""
cls = type(self)
# noinspection PyArgumentList
return cls([
literal.encode()
for literal in self.literals
])
class LiteralExtended(part_a.Literal):
def encode(self) -> 'LiteralExtended':
cls = type(self)
# noinspection PyArgumentList
return cls(json.dumps(self.code), self.code)
Challenge.main()
challenge = Challenge()