Solved 2024/13 P2
This commit is contained in:
parent
2926202888
commit
486144352b
@ -83,8 +83,6 @@ tokens you would have to spend to win all possible prizes?*
|
||||
|
||||
Your puzzle answer was `30973`.
|
||||
|
||||
The first half of this puzzle is complete! It provides one gold star: \*
|
||||
|
||||
## \-\-- Part Two \-\-- {#part2}
|
||||
|
||||
As you go to win the first prize, you discover that the claw is nowhere
|
||||
@ -119,8 +117,14 @@ Using the corrected prize coordinates, figure out how to win as many
|
||||
prizes as possible. *What is the fewest tokens you would have to spend
|
||||
to win all possible prizes?*
|
||||
|
||||
Answer:
|
||||
Your puzzle answer was `95688837203288`.
|
||||
|
||||
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](/2024) and
|
||||
try another puzzle.
|
||||
|
||||
If you still want to see it, you can [get your puzzle
|
||||
input](13/input).
|
||||
|
||||
|
@ -14,7 +14,6 @@ input_f = 'input'
|
||||
# #
|
||||
#########################################
|
||||
def part1():
|
||||
|
||||
instructions = []
|
||||
|
||||
with open(input_f) as file:
|
||||
@ -23,7 +22,6 @@ def part1():
|
||||
if match:
|
||||
instructions.append(list2int([match.group(1),match.group(2)]))
|
||||
|
||||
#print(instructions)
|
||||
a_cost = 3
|
||||
b_cost = 1
|
||||
|
||||
@ -34,7 +32,6 @@ def part1():
|
||||
result = 0
|
||||
|
||||
for idx, inst in enumerate(instructions):
|
||||
#print(inst)
|
||||
|
||||
if idx%3 == 0:
|
||||
a = (inst[0],inst[1])
|
||||
@ -46,15 +43,13 @@ def part1():
|
||||
eq2 = Eq(a[1]*x + b[1]*y,r[1])
|
||||
|
||||
s = solve((eq1,eq2),(x,y))
|
||||
#print(s)
|
||||
if s:
|
||||
result += s[x]*a_cost
|
||||
result += s[y]*b_cost
|
||||
#input()
|
||||
return result
|
||||
|
||||
start_time = time.time()
|
||||
print('Part 1:',part1(), '\t\t', round((time.time() - start_time)*1000), 'ms')
|
||||
#rint('Part 1:',part1(), '\t\t', round((time.time() - start_time)*1000), 'ms')
|
||||
|
||||
|
||||
#########################################
|
||||
@ -62,8 +57,43 @@ print('Part 1:',part1(), '\t\t', round((time.time() - start_time)*1000), 'ms')
|
||||
# Part 2 #
|
||||
# #
|
||||
#########################################
|
||||
def part1():
|
||||
return
|
||||
def part2():
|
||||
instructions = []
|
||||
|
||||
with open(input_f) as file:
|
||||
for line in file:
|
||||
match = get_re(r".*X[\+|=](\d+), Y[\+|=](\d+)",line.rstrip())
|
||||
if match:
|
||||
instructions.append(list2int([match.group(1),match.group(2)]))
|
||||
|
||||
a_cost = 3
|
||||
b_cost = 1
|
||||
|
||||
a = ()
|
||||
b = ()
|
||||
r = ()
|
||||
x,y = symbols('x y',integer=True)
|
||||
result = 0
|
||||
|
||||
for idx, inst in enumerate(instructions):
|
||||
|
||||
if idx%3 == 0:
|
||||
a = (inst[0],inst[1])
|
||||
elif idx%3 == 1:
|
||||
b = (inst[0],inst[1])
|
||||
elif idx%3 == 2:
|
||||
r = (inst[0]+10000000000000,inst[1]+10000000000000)
|
||||
eq1 = Eq(a[0]*x + b[0]*y,r[0])
|
||||
eq2 = Eq(a[1]*x + b[1]*y,r[1])
|
||||
|
||||
s = solve((eq1,eq2),(x,y))
|
||||
if s:
|
||||
result += s[x]*a_cost
|
||||
result += s[y]*b_cost
|
||||
#input()
|
||||
return result
|
||||
|
||||
start_time = time.time()
|
||||
print('Part 2:',part1(), '\t\t', round((time.time() - start_time)*1000), 'ms')
|
||||
|
||||
start_time = time.time()
|
||||
print('Part 2:',part2(), '\t\t', round((time.time() - start_time)*1000), 'ms')
|
Loading…
Reference in New Issue
Block a user