r/adventofcode • u/bjnord • Dec 21 '22
Tutorial [2022 Day 21 (Part 2)] Another example
If the example passes your part 2 code but your puzzle input doesn't, this example might help; you should get 19 for part 2:
root: juli + josi
juli: amee + alex
amee: buki * abby
buki: 5
abby: 4
alex: 4
josi: benj / mark
benj: 360
mark: emly - humn
emly: 34
humn: 0
47
Upvotes
8
u/Cue_23 Dec 21 '22
You should even test
humnto be left- and right-hand side of-and/.I thought it would be easy to come up with a better example, turns out I swapped the operators in my head :D But here it is (answer is still 19):
3
u/IsatisCrucifer Dec 21 '22
Does your input having
humnbe on the right branch of the division? Since binary-search solutions exists it seems like this is not the case, although I can be wrong.7
u/woffle-kat Dec 22 '22
Oh boy, I'd covered the division operator, but missed the left/right side check on the minus operator, this input pointed me directly to the issue. Thanks a lot!
3
u/RoccoDeveloping Dec 21 '22
Thanks! My non-commutative implementation was wrong, this helped me find the issue.
3
u/daggerdragon Dec 21 '22
Changed flair from
SpoilerstoTutorial.2
u/Eru4nno Dec 22 '22 edited Dec 22 '22
Thanks for that example. I've adjusted my code, now two of the test inputs are passing, yet real data still produces same incorrect output... Basically if my left node has value then I'm not mirroring operation sign for divison and substraction. But for some reason this happens throughout the process : 2 / -103914152560478 and I have 809.98782968746869856 nonsese at the end EDIT: Actualy the third test case showed mi that I also need to reverse arguments when +/* and x was on the left side... sigh... Now it works!
1
u/j3r3mias Dec 21 '22
I believe that
34is also a valid answer for this input (formark = 15).1
u/Armanlex Dec 21 '22
I LOVE YOUUUUUUUUUUUUU!!!!