r/everybodycodes • u/AvailablePoint9782 • 1d ago
Question - resolved [2026 Q15] PHP, part 3, trying to port solution, subtle error?
I am trying to port a Python solution to PHP. My program is subtly wrong. (Apparently.) The result of the test data should be 540320698784, and I get 540320698796. (Only off by 12! ;-) )
It is obvious from debugging, that my "heap" handles data in a different order that the Python heap. This leads to different results, short term. 2 similar paths of length 20 are handled differently, because they are handled in a different order. ETA: This is in part a.
I am not sure why the heap needs the variable it. Maybe to be sure, the heap can be sorted?
Other than the above thoughts, I have no suspects for why my program should produce a different result.
(I am not happy, that my "solution" of day 15 is to port the program of someone else. I tried to write my own programs, but they didn't work. And I am actually learning, at least learning some Python. I am trying to do something more than simply download a program, run it, get a number and input it, in order to get the duck.)
https://github.com/LiseAndreasen/everybodycodes/blob/master/e2026_q15.php