mirror of
https://github.com/Crocmagnon/advent-of-code.git
synced 2024-12-22 05:41:51 +01:00
Implement day 5 part 2
This commit is contained in:
parent
84d0a06e9a
commit
476fb7e0ee
3 changed files with 33 additions and 2 deletions
|
@ -3,7 +3,10 @@ NUMBER_OF_PARAMS_MAP = {
|
|||
2: 3,
|
||||
3: 1,
|
||||
4: 1,
|
||||
99: 0,
|
||||
5: 2,
|
||||
6: 2,
|
||||
7: 3,
|
||||
8: 3,
|
||||
}
|
||||
|
||||
LAST_IS_RESULT_MAP = {
|
||||
|
@ -11,6 +14,10 @@ LAST_IS_RESULT_MAP = {
|
|||
2: True,
|
||||
3: True,
|
||||
4: False,
|
||||
5: False,
|
||||
6: False,
|
||||
7: True,
|
||||
8: True,
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,10 +69,32 @@ def compute(lst):
|
|||
program[params[2]] = params[0] * params[1]
|
||||
elif code == 3:
|
||||
# Input
|
||||
program[params[0]] = int(input(f"Input for instruction {pointer}"))
|
||||
program[params[0]] = int(input(f"Input for instruction {pointer}\n> "))
|
||||
elif code == 4:
|
||||
# Output
|
||||
print(params[0])
|
||||
elif code == 5:
|
||||
# Jump if true
|
||||
if params[0] != 0:
|
||||
pointer = params[1]
|
||||
pointer_moved = True
|
||||
elif code == 6:
|
||||
# Jump if false
|
||||
if params[0] == 0:
|
||||
pointer = params[1]
|
||||
pointer_moved = True
|
||||
elif code == 7:
|
||||
# Less than
|
||||
if params[0] < params[1]:
|
||||
program[params[2]] = 1
|
||||
else:
|
||||
program[params[2]] = 0
|
||||
elif code == 8:
|
||||
# Equals
|
||||
if params[0] == params[1]:
|
||||
program[params[2]] = 1
|
||||
else:
|
||||
program[params[2]] = 0
|
||||
|
||||
else:
|
||||
raise ValueError(f"Something bad happened, code={code}")
|
||||
|
|
1
2019/inputs/day05-ex1
Normal file
1
2019/inputs/day05-ex1
Normal file
|
@ -0,0 +1 @@
|
|||
3,9,8,9,10,9,4,9,99,-1,8
|
1
2019/inputs/day05-ex2
Normal file
1
2019/inputs/day05-ex2
Normal file
|
@ -0,0 +1 @@
|
|||
3,21,1008,21,8,20,1005,20,22,107,8,21,20,1006,20,31,1106,0,36,98,0,0,1002,21,125,20,4,20,1105,1,46,104,999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99
|
Loading…
Reference in a new issue