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

Neil Banman

12/12/2023, 12:51 AM
In years' past I've fleshed out my
Grid
class and made it quite powerful and flexible. But this year I've really been enjoying using the input
String
directly as a virtual 2-D grid. You just need to track the width, after that, you can move around in any direction. The line breaks delineate the left and right sides of (almost) every row. Top and bottom are handled by using
getOrNull
. This also handles left of 0 and right of
lastIndex
. Does anyone else prefer working with a 1-D String rather than
lines()
or
List<List<E>>
?
e

ephemient

12/12/2023, 4:17 AM
I try not to assume every line has the same length
b

bj0

12/12/2023, 4:33 AM
I pretty much always convert any grid into a
Map
of coordinate to content.
n

Neil Banman

12/12/2023, 4:52 AM
The yang to my yin.
@ephemient that may be good hygiene but for AoC to my knowledge all graphical representations of maps have been rectangular.
b

bj0

12/12/2023, 4:59 AM
except for that one cube one...
n

Neil Banman

12/12/2023, 5:00 AM
And maybe that one that had teleporters on the outside that matched up with ones on the inside. Can’t remember if that one had consistent spacing.
And, I suppose, technically, today's.
e

ephemient

12/12/2023, 11:44 AM
yes, aoc inputs for mazes are usually nice. but my test data is just strings inside source code and might have spaces auto-stripped by the editor, for example, so I make my code safe
k

Kroppeb

12/12/2023, 1:26 PM
@Neil Banman
And maybe that one that had teleporters on the outside that matched up with ones on the inside. Can’t remember if that one had consistent spacing.
It had extra spacing on the end yes. I know that very well cause I was relying on it, but IntelliJ was stripping the spaces at the end when I pasted them into the file, giving me the weirdest errors that took me way to long to figure out
From then on out, I used a script to download my data
3 Views