Unable to load image

Advent of Code 2022 : Day 9

grate filter edition

:#marseycapyhacker:

17
Jump in the discussion.

No email address required.

still ezpz

![](/images/16705662634689796.webp)

Jump in the discussion.

No email address required.

![](/images/16705686200084054.webp)

Why even np if you don't FULLY GAY VECTORIZE it?

Shouldn't it be something like tail += np.sign(head - tail) ?

Jump in the discussion.

No email address required.

because i am very new to coding and have no idea how np works or what features it has

the reason i used np here is because i googled 'python get sign' and it told me to do this

i see a lot of people here using np stuff though so i should probably look into it

Jump in the discussion.

No email address required.

np is so awesome, when you begin to get just how much you can vectorize it's like seeing through the matrix. My fav example probably: this is a game of life implementation:

def _life(field):
    nb = sum(np.roll(field, (i - 1, j - 1), axis=(0, 1)) for i in range(3) for j in range(3))
    return (field & (nb == 4)) | (nb == 3)

(and also this is why I think that representing coordinates as complex numbers is a bit of a gimmick: when it works, all right it works, but even in this pretty simple task np.sign was a way more elegant way to tackle the core of the problem)

Jump in the discussion.

No email address required.

vectors

seeing through the matrix

:taylaugh:

Jump in the discussion.

No email address required.

decided to give it a try and it ended up being much easier and much nicer

thanks king :marseyexcited:

![](/images/16705918761947992.webp)

Jump in the discussion.

No email address required.

Ye this is what I'm talking about. Also: if any(np.abs(this_knot - prev_knot) > 1):, amirite?

Jump in the discussion.

No email address required.

you can just create a new array like that? this is madness lmao, that's so good. gonna have to find a way to learn this stuff fast

Jump in the discussion.

No email address required.

I used math.copysign(1, x) because I've managed to avoid a numpy import so far and I think that's my new goal for this thing

Jump in the discussion.

No email address required.

Link copied to clipboard
Action successful!
Error, please refresh the page and try again.