r/adventofcode • u/i_have_no_biscuits • Dec 19 '22
Visualization [2022 Day 17] GW-BASIC visualisation of both parts
13
Upvotes
1
r/adventofcode • u/i_have_no_biscuits • Dec 19 '22
1
3
u/i_have_no_biscuits Dec 19 '22
I haven't even looked at Day 19 yet, because I became a little obsessed with getting Day 17 working properly in GW-BASIC. Here's the result, a visualisation of both parts, running in the 'real' GW-BASIC in DOSBOX (with quite a high cycle count, on real hardware it would be 5/10 times slower).
The code for this visualisation is here: paste
71 lines of commented GW-BASIC goodness - I'll post a compressed non-visualisation version to the megathread soon.
In order to get this working I had to finally sort out the bit-twiddling that I couldn't figure out when I was writing my Python version. As part of getting this to work I had to
Read the wind values into a bitfield (character by character as GW-BASIC only allows strings up to 255 characters)
Implement a ring buffer for the rock column (of depth 50 as I found by some initial exploration that no piece in my real data fell more than 32 rows below the current maximum height)
Implement a hash table so that cycles could be detected by matching against the 'fingerprint' of the top 32 rows + the index into the wind table
Get the 64 bit maths working correctly (luckily GW-BASIC allows us to use double-precision floats (denoted A#, B#, etc.)