-
Notifications
You must be signed in to change notification settings - Fork 0
/
part_b.py
executable file
·36 lines (27 loc) · 891 Bytes
/
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
#!/usr/bin/env python3
import utils
from year_2019.day_02.part_a import get_program_result
class Challenge(utils.BaseChallenge):
def solve(self, _input, debug=False):
"""
>>> Challenge().default_solve()
8226
"""
noun, verb = find_verb_and_noun(_input, 19690720)
return 100 * noun + verb
def find_verb_and_noun(program_text, expected_value):
"""
>>> _input = challenge.input
>>> find_verb_and_noun(_input, 2890696)
(12, 2)
>>> find_verb_and_noun(_input, 19690720)
(82, 26)
"""
for noun in range(100):
for verb in range(100):
value = get_program_result(program_text, {1: noun, 2: verb})
if value == expected_value:
return noun, verb
raise Exception(f"Could not find and noun to result in {expected_value}")
Challenge.main()
challenge = Challenge()