https://kotlinlang.org logo
#advent-of-code
Title
# advent-of-code
t

Tolly Kulczycki

12/05/2023, 8:55 PM
I'm having an intense issue and tried looking through the no-spoilers thread but no dice, need help, code in thread
Untitled.cpp
my approach is to go forward with ranges of seeds
I imagine it's an off-by-one error... somewhere in there
d

Dan Fingal-Surma

12/05/2023, 9:05 PM
seedRanges.addAll(ranges.second)
does not seem correct, that puts the transformed range back into the queue to be processed from the beginning as if it were a seed range
you want to proceed in stages, take all the seed input ranges and produce the soil ranges, then take the soil ranges and produce the fertilizer ranges, etc.
Looking at transformRange I don’t see where it projects it into the destination space
I had this error at one point as well
you still need your transform function from part 1,
currSeed = option[0] + (currSeed - option[1])
the idea to move forward with ranges is the key insight which you already have
t

Tolly Kulczycki

12/05/2023, 9:10 PM
so for me mapping is this:
Copy code
60 56 37
56 93 4
and an option is this:
Copy code
60 56 37
and so transform range takes a range and produces a list of ranges that
are either outside below, outside above, or modified
and the ones outside get back onto the stack
while if something has been modified then it breaks
and moves onto the next stage
d

Dan Fingal-Surma

12/05/2023, 9:14 PM
how much spoilers do you want in terms of the algorithm
t

Tolly Kulczycki

12/05/2023, 9:15 PM
I can tolerate some, already looked at some of the answers
d

Dan Fingal-Surma

12/05/2023, 9:18 PM
so at phase N, for each input range, you want to produce the set of output ranges. then feed all produced output ranges into phase N + 1. If you put it back into the deque, it will start processing that range from phase 0, which is not correct. i.e. applying a seed-to-soil transform on a light range.
t

Tolly Kulczycki

12/05/2023, 9:19 PM
OH
That's the problem
I see now
okay
d

Dan Fingal-Surma

12/05/2023, 9:20 PM
producing the set of output ranges for a given input range has 2 steps, at least in my impl: determine the interior split points based on the mapping ranges, which generates a set of (contiguous) ranges, then project those ranges into the destination space
t

Tolly Kulczycki

12/05/2023, 9:20 PM
That makes so much sense, thank you Dan!
👍 1
Okay, managed to figure it out (albeit with your knowledge, another tutorial and some reading) but I did it!
🎉 1
2 Views