I'm kind of stuck on the second part, all the exam...
# advent-of-code
g
I'm kind of stuck on the second part, all the examples work, but apparently my answer is wrong ­čś×
n
Spoilers There are some helpful threads on Reddit about easy-to-miss details, for example: https://www.reddit.com/r/adventofcode/comments/a6f100/day_15_details_easy_to_be_wrong_on/
g
Thanks, the corner cases are nice, but my code can already handle them. I really don't get if the first part is fine, and the examples of the second part go fine, what could cause it not to work..
k
Literally all tests passed on my code for both part 1 and 2, but I still did this edge case wrong:
Copy code
#######
#######
#.E..G#
#.#####
#G#####
#######
#######
g
So when there are two possible targets at the same distance the target closer in reading order should be taken? Cause currently I start searching from top, left, right, down to the first I find. That would be fixable.
k
That's exactly what I did as well, but yes you really need to find all targets and then pick the first one in reading order.
g
Yes, I now keep a list with y,x,move of potential targets, keep going when I find one, stop looping when I find at least one, then sort and return the first move..
k
So the edge case works now? The Elf moves the the right?
g
yes, and the solution for the second part is correct now, finally
k
Nice!
g
Also because I needed to use the list instead of returning directly it was much easier to put it in a separate function, so my most complex function was 50, now still 26, but I'm not going to touch it anymore.
k
How long does it take your code to run now?
g
About half a second for the second part
k
Dammit, why is everyones code so fast!
g
Could be the machine instead of the code, I'm on a brand new MacBook Pro cause the other one died after only two years..
k
Doubt that, my pc is quite new as well. I'll try to closely compare codes when I find the time simple smile