-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2.py
33 lines (22 loc) · 782 Bytes
/
part2.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
from typing import List
import json
import part1
from part1 import NOT_VALID
def solution(inp: List[str]) -> int:
original = [json.loads(z) for z in inp if z]
original.append([[2]])
original.append([[6]])
ordered = []
while original:
for current in original:
if all(part1.is_valid(current, other) != NOT_VALID for other in original):
original.remove(current)
ordered.append(current)
return (ordered.index([[2]]) + 1) * (ordered.index([[6]]) + 1)
def result(inp: List[str]) -> int:
return solution(inp)
def test(examples: List[List[str]]) -> None:
example = 0
exp = 140
res = result(examples[example])
assert res == exp, f"example {example}: result was {res}, expected {exp}"