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

Safi K

12/05/2023, 8:49 PM
My solution works on testInput, but when I run it on the actual input, I run out of memory. What should I do?
r

Riccardo Lippolis

12/05/2023, 8:50 PM
have a look at this thread, where today's problem is being discussed without providing actual solutions, which might give you some pointers: https://kotlinlang.slack.com/archives/C87V9MQFK/p1701767182803779
d

Dan Fingal-Surma

12/05/2023, 8:57 PM
Please thread questions in the “Advent of Code Day N” thread
s

Safi K

12/05/2023, 8:57 PM
I am afraid I still haven't found anything.. The problem is that my code runs out of solution while adding seeds from the input, not in finding the minimum location or any other values..
in here
d

Dan Fingal-Surma

12/05/2023, 8:58 PM
You should not try to brute force this
s

Safi K

12/05/2023, 8:59 PM
The part that I add value to the seed, exactly?
d

Dan Fingal-Surma

12/05/2023, 8:59 PM
Yes the proper solution doesn’t check all seeds in the range
s

Safi K

12/05/2023, 9:00 PM
oh, okay. I'll try to find a way. Thanks
n

Neil Banman

12/05/2023, 9:04 PM
While I agree that brute-force is not the way to go, if you want to try it the trick is to generate the seeds on-the-fly via sequence or regular imperative loop. Then you only need to track the lowest result you've found, so you don't run out of memory.
s

Safi K

12/05/2023, 9:09 PM
So, something like this: For each value in sequence, calculate the location of that seed, store the location in a variable and if the next value has a lower location, store that instead, and return the location at the end, which is of course the min location value. Is this correct?
d

Dan Fingal-Surma

12/05/2023, 9:09 PM
yes you could do that, it may take about 10 minutes to run depending on how fast your seed->location method is
s

Safi K

12/05/2023, 9:10 PM
Okayy, thank you very much. I'll try it right away.
c

Charles Flynn

12/05/2023, 9:18 PM
Unlike other problems of this ilk you can get away with brute forcing this. Just make sure you're not storing lists in memory.
s

Safi K

12/05/2023, 9:39 PM
So, I implemented my program to get rid of the memory error. Just wondering, does changing this value boost the run time or not?
image.png
n

Neil Banman

12/05/2023, 9:41 PM
It should make it run faster since you're not commiting things to memory and recalling them again. But it will still be very slow.
s

Safi K

12/05/2023, 9:44 PM
okay, so you solved the part 2 already, right? How much time did your solution take?
I mean, if it's longer than 10 mins, I have a thing to do and, come back,,
d

Dan Fingal-Surma

12/05/2023, 9:45 PM
79 micros
s

Safi K

12/05/2023, 9:46 PM
79 micro seconds??
n

Neil Banman

12/05/2023, 9:46 PM
I did a bruteforce solution but I suspect it was different than yours. I didn't start with the seeds. I started with the output. I tried 0, ran it backwards through the maps, and ended up with the starting seed is to arrive at 0. Then I checked whether that seed was in the startingSeed ranges. If not, I proceeded to 1, then 2, etc. until one matched. That took 10 seconds.
I then refactored to how all the cool kids are doing it, and it was 26ms. Not as fast as Dan, but enough to call it a day.
d

Dan Fingal-Surma

12/05/2023, 9:47 PM
Yes, not using brute force
s

Safi K

12/05/2023, 9:48 PM
Wow, mine definitely looks like an infinite loop, compared to yours, haha. But I hope it doesn't end with a bug or wrong answer after waiting that long,
n

Neil Banman

12/05/2023, 9:49 PM
That's one reason not to carry on trying to get the naive bruteforce to work. Especially dealing with ranges, very easy for off-by-one errors. Bruteforce is really hard to debug, especially if you have to wait 10 minutes to see if you got it wrong!
d

Dan Fingal-Surma

12/05/2023, 9:50 PM
Yes one of the guidelines is “every problem has a solution that completes in at most 15 seconds on ten-year-old hardware”
1
s

Safi K

12/05/2023, 9:52 PM
Haha you guys are right. But the problem is that I haven't learned a lot about data structures, algorithms or optimization methods yet. So, implementing any other solution is difficult for me.
r

Riccardo Lippolis

12/05/2023, 9:52 PM
regarding the memory setting you're mentioning here: https://kotlinlang.slack.com/archives/C87V9MQFK/p1701812401785649?thread_ts=1701809361.246379&cid=C87V9MQFK, I think that's only setting the max heap size for the IntelliJ IDE itself, not for any program you're running from your IDE, because that will start a new Java process (with its own memory settings)
n

Neil Banman

12/05/2023, 9:54 PM
Haha you guys are right. But the problem is that I haven't learned a lot about data structures, algorithms or optimization methods yet.
Don't let that stop you! My last computer class was in high school in 1995. And I'm a lawyer, not a programmer. You learn by doing (and asking for help... and reading wikipedia...)!
s

Safi K

12/05/2023, 9:54 PM
Hmm, so it's more useful for Android Studio since it deals with emulator and decomposition. But not as much for Intellij
r

Riccardo Lippolis

12/05/2023, 9:55 PM
@Safi K don't give up, even if you don't succeed at solving all the problems every day, it's all about learning and having fun. If that means at some point you get stuck and have to look at other people's solutions, don't feel bad about that. We all start somewhere, I've been doing AoC for a few times now and it's a struggle at times, but keep it fun for yourself! Don't feel the need to compete with others (I'm having fun even with my hacky solutions that are far from the top solutions 😁)
n

Neil Banman

12/05/2023, 9:55 PM
This is an insanely difficult year. Usually the first 10 days are way easier than this.
d

Dan Fingal-Surma

12/05/2023, 9:56 PM
Yeah my response to this question is, thanks for the math homework 😄
😁 1
First it was wall of text crits you for 20 damage
s

Safi K

12/05/2023, 9:58 PM
Don't let that stop you! My last computer class was in high school in 1995. And I'm a lawyer, not a programmer. You learn by doing (and asking for help... and reading wikipedia...)!
That's true, thank you. I will try to start solving problems earlier tomorrow, so I'll have more time to find better solutions and optimizations. Right now, I really am in a hurry..
don't give up, even if you don't succeed at solving all the problems every day, it's all about learning and having fun..
Thank you, I'll try my best. I was not able to solve day three's second part because I misunderstood something, so I moved on to day 4 anyways, and now to day 5. Yeah, comparing to others is the worst. I do it sometimes but with IG models actually, than other programmers lol 😂 And it's my first year doing AoC.
c

Charles Flynn

12/05/2023, 10:03 PM
Brute forcing mine takes about 5 minutes
s

Safi K

12/05/2023, 10:03 PM
Well, it's been about 20 mins and the program is still running. I think it's useless to wait more for it..
I should find a better solution now.
j

Johannes Gätjen

12/05/2023, 10:06 PM
a tip for bruteforcing: have some periodic output to show the progress, that way you can estimate how much longer you need to wait. A friend of mine did today's problem the brute force way and waited one hour for the solution.
👍 1
n

Neil Banman

12/05/2023, 10:07 PM
Yes one of the guidelines is “every problem has a solution that completes in at most 15 seconds on ten-year-old hardware”
The funny thing is that the most compute-intensive problems are in the early years when 10 year old computers were ancient by today's standards. All that MD5 hashing... hard to come up with a shortcut for those. I got 2016 day 14 down to 2 seconds (cold start) using parallelism on my 2018-era Ryzen 5 CPU. In 2006, Intel had just released their first dual-core desktop offering. I can't imagine doing that many hashes on that in 15 seconds without getting awfully close to bare metal.
s

Safi K

12/05/2023, 10:08 PM
a tip for bruteforcing: have some periodic output to show the progress, that way you can estimate how much longer you need to wait. A friend of mine did today's problem the brute force way and waited one hour for the solution.
Thank you, I had to do it now haha.
5 Views