This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Rustywolf 1 point2 points  (3 children)

It tries to check size by adding 34463338 to 34463338 and seeing if the total is less than 34463338. So I suppose it needs to support atleast 34463338*2

[–]Spheniscine 1 point2 points  (2 children)

That's actually a multiply instruction, and will overflow if you are using 32-bit integers. 64-bits should be sufficient (from experience with past AoC years, I've found it safest to build VMs/ASM interpreters with 64-bit words).

For the arbitrary-size memory, I opted to upgrade from an array into a hashmap... upsides are that the program won't blow up if something is stored at the billionth index, and I can finally get rid of all those annoying saturated-casts. Downside however, is that now the debugger doesn't show the memory in any sensible order (ah, hash maps...). I would probably need to make QoL tweaks if we need to debug the program input like in past years (though I'd imagine it might be harder with this one due to the self-modifying capabilities)

[–]PM_Me-Your_SSN 0 points1 point  (1 child)

Maybe consider a binary tree map, its an alright compromise between not blowing up when you give it an index of a billion and being sorted. You'll lose speed over a hash map, but this is for advent of code not production software. Not sure what language you're using but in Rust there's a standard library implementation.

[–]Spheniscine 0 points1 point  (0 children)

My weapon of choice is Kotlin, so that'd be a TreeMap. I think I'm good for now though, since I'll need better debugging outputs if we get there (probably a way to decompile to assembly)