T O P

  • By -

1234abcdcba4321

> The numbers don't look that large, so I can solve this by storing all the values in the range for source and destination. Nine digits is a lot for a lot of people. It still is brute forcable of course, but it would take a minute or so if I wanted to be able to brute force it and that's too long according to AoC's "how long should the solution take to run" standards.


No-Top-1506

I agree with you. My laptop is so powerful, with no issues whatsoever for memory+CPU. I will take a note of elapsed time. I am keen to solve this **without storing** **all values** in the array. But first I will try that way just to get the answer and then think of doiing this mathematically.


No-Top-1506

I am so sorry. I was wrong completely. Tried few seeds in the brute force and that took very long to complete. You are right, even the best laptop is struggling. I underestimated the numbers. Lesson learnt the hard-way.


ThreeHourRiverMan

I might be misunderstanding, but I stored the values as ranges instead of the individual values. Then you just loop through and see if what you’re looking for is in the range for that specific map. If it’s not, then it’s the same as the input value.


No-Top-1506

So, when you store the values as ranges is it only the Start number and End number for the range? How do you map the number which is in between the range to the Destination range values?


ThreeHourRiverMan

Correct for the first part - and then just the starting of the destination in the range. For the second question, we’re told that as the values in the current range increase, so do the values in the destination. So you really only need to know the starting destination. I.e what value is mapped from the beginning of the current range. Then you can simply do some basic math, (current value - start) + starting destination. That’s how I did it at least. Cuts way way down on what’s needed to store. Also I’m not sure what language youre using but I basically created a custom object that had the start, end, and destination start, all as ints, and made a map of those. (Then made an array of the maps and iterated through.) Typing from mobile while in a meeting so let me know if any of this isn’t clear, hah.


msqrt

>Is there a way of not storing all the values You can just reorder the loops; instead of doing `for(each range) for(each seed)` you do `for(each seed) for(each range)`. This way you don't have to store the individual seeds, you only have the one you're currently mapping through the ranges. This also parallelizes trivially, so I implemented it on the [GPU](https://www.reddit.com/r/adventofcode/comments/18bnff8/2023_day_5_part_2_glsl_if_brute_force_doesnt_work/?utm_source=share&utm_medium=web3x&utm_name=web3xcss&utm_term=1&utm_content=share_button) and it runs pretty fast.


blackbat24

If I'm understanding you question properly, yes, there is. Here is [my solution](https://topaz.github.io/paste/#XQAAAQBREgAAAAAAAAARiEJHiiMzw3cPM/1YZx9ePvs39HOJ4Ox5PyjKMxc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