Solved 2024/03 P1+P2
This commit is contained in:
+8
-4
@@ -28,8 +28,6 @@ instruction invoked?*
|
||||
|
||||
Your puzzle answer was `5929`.
|
||||
|
||||
The first half of this puzzle is complete! It provides one gold star: \*
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
Now, it\'s time to fix the problem.
|
||||
@@ -50,8 +48,14 @@ it wouldn\'t even need to run the program.
|
||||
After setting register `a` to `1`, if the program were to run to
|
||||
completion, *what value would be left in register `h`?*
|
||||
|
||||
Answer:
|
||||
Your puzzle answer was `907`.
|
||||
|
||||
Although it hasn\'t changed, you can still [get your puzzle
|
||||
Both parts of this puzzle are complete! They provide two gold stars:
|
||||
\*\*
|
||||
|
||||
At this point, you should [return to your Advent calendar](/2017) and
|
||||
try another puzzle.
|
||||
|
||||
If you still want to see it, you can [get your puzzle
|
||||
input](23/input).
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
set e 2
|
||||
set g d
|
||||
mul g e
|
||||
sub g b
|
||||
jnz g 2
|
||||
set f 0
|
||||
sub e -1
|
||||
set g e
|
||||
sub g b
|
||||
jnz g -8
|
||||
sub d -1
|
||||
set g d
|
||||
sub g b
|
||||
jnz g -13
|
||||
jnz f 2
|
||||
sub h -1
|
||||
set g b
|
||||
sub g c
|
||||
jnz g 2
|
||||
jnz 1 3
|
||||
sub b -17
|
||||
jnz 1 -23
|
||||
@@ -0,0 +1,31 @@
|
||||
a = 1
|
||||
b = 79 * 100 + 100000
|
||||
c = 79 * 100 + 100000 + 17000
|
||||
|
||||
9. set f 1
|
||||
10. set d 2
|
||||
11. set e 2
|
||||
|
||||
12.
|
||||
|
||||
|
||||
if g != 0 jump to 12
|
||||
g = d * e - b
|
||||
|
||||
if g != 0
|
||||
f = 0
|
||||
g = (e - 1) - b
|
||||
|
||||
21. sub d -1
|
||||
22. set g d
|
||||
23. sub g b
|
||||
24. jnz g -13 jump to 11
|
||||
25. jnz f 2 jump to 27
|
||||
26. sub h -1
|
||||
27. set g b
|
||||
28. sub g c
|
||||
29. jnz g 2
|
||||
30. jnz 1 3
|
||||
31. sub b -17
|
||||
32. jnz 1 -23 jump to 9
|
||||
|
||||
+72
-4
@@ -3,10 +3,10 @@ import sys,re
|
||||
from pprint import pprint
|
||||
sys.path.insert(0, '../../')
|
||||
from fred import list2int
|
||||
|
||||
from math import sqrt
|
||||
input_f = 'input'
|
||||
|
||||
part = 1
|
||||
part = 3
|
||||
#########################################
|
||||
# #
|
||||
# Part 1 #
|
||||
@@ -34,7 +34,7 @@ if part == 1:
|
||||
instructions = []
|
||||
|
||||
Sets = {
|
||||
'a': 1,
|
||||
'a': 0,
|
||||
'b': 0,
|
||||
'c': 0,
|
||||
'd': 0,
|
||||
@@ -81,4 +81,72 @@ if part == 1:
|
||||
# #
|
||||
#########################################
|
||||
if part == 2:
|
||||
exit()
|
||||
instructions = []
|
||||
|
||||
Sets = {
|
||||
'a': 1,
|
||||
'b': 107900,
|
||||
'c': 124900,
|
||||
'd': 3,
|
||||
'e': 107900,
|
||||
'f': 1,
|
||||
'g': -107897,
|
||||
'h': 0
|
||||
}
|
||||
|
||||
count = 0
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
instructions.append(list(parse_input(line.rstrip())))
|
||||
|
||||
intr = 0
|
||||
while 0 <= intr < len(instructions):
|
||||
|
||||
i = instructions[intr]
|
||||
|
||||
x = i[1]
|
||||
y = i[2]
|
||||
|
||||
if i[0] == 'set':
|
||||
Sets[x] = sets_return(y,Sets)
|
||||
|
||||
elif i[0] == 'sub':
|
||||
Sets[x] -= sets_return(y,Sets)
|
||||
|
||||
elif i[0] == 'mul':
|
||||
Sets[x] *= sets_return(y,Sets)
|
||||
count += 1
|
||||
|
||||
elif i[0] == 'jnz':
|
||||
if sets_return(x,Sets) != 0:
|
||||
intr += sets_return(y,Sets)-1
|
||||
intr += 1
|
||||
print(i)
|
||||
print(Sets)
|
||||
input()
|
||||
print(count)
|
||||
|
||||
|
||||
if part == 3:
|
||||
b = 107900
|
||||
d = 2
|
||||
e = 2
|
||||
h = 0
|
||||
for x in range(107900,124900,17):
|
||||
for y in range(2,x):
|
||||
if x%y == 0:
|
||||
print(x,y,h)
|
||||
h+=1
|
||||
print(h)
|
||||
|
||||
# def is_composite(n):
|
||||
# if n < 2:
|
||||
# return False
|
||||
# for i in range(2, int(sqrt(n)) + 1):
|
||||
# if n % i == 0:
|
||||
# return True
|
||||
# return False
|
||||
|
||||
# h = sum(1 for b in range(107900, 124901, 17) if is_composite(b))
|
||||
# print(h)
|
||||
Reference in New Issue
Block a user