What do you need to represent?
# advent-of-code
o
What do you need to represent?
k
A grid with positive x and y coordinates where the value at
(x, y)
depends on the values at
(x-1, y)
and
(x, y-1)
. It also needs to be lazy.
o
Is size known?
k
Nope.
Otherwise making it lazy wouldn't be necessary.
o
I would try a linear Int array with diagonal encoding
Copy code
0136
247
58
9
Indicies would go like this
Calculating index of down or right cell is pretty trivial, and you can resize it like normal array (x2)
k
But then if you access
(0, 100)
you have to calculate a bunch of excess stuff, right?
o
allocate yes, calculate no
k
I was going to say that the ratio for this challenge is 7/713, but we do a BFS on it so it should pretty much be even.
I'll give it a shot!
Finally got it:
i = (x + y) * (x + y + 1) / 2 + y
. It's too early for math!
But the array works! It's about 30% faster than the lists.
o
30% is quite an improvement!
👍 1