Ivy remains a good choice for
[#]AdventOfCode.
Day 1:
sample = transp read "sample.txt"
op sort x = x[up x]
op solve x = +/abs (sort x[1]) - sort x[2]
solve sample
op solve2 x = +/x[1] * +/x[1] o.== x[2]
solve2 sample
https://adventofcode.com
(Ivy in 2021: https://www.youtube.com/playlist?list=PLrwpzH1_9ufMLOB6BAdzO08Qx-9jHGfGg)
=> More informations about this toot | More toots from rsc@hachyderm.io
Day 2:
sample = read "sample.txt"
op delta x = (1 drop x) - -1 drop x
op safeInc x = &/ (delta x) in 1 2 3
op safeDec x = &/ (delta x) in -1 -2 -3
op safe x = (safeInc x) | safeDec x
op solve x = +/ safe@ x
solve sample
op i delete x = (i != iota rho x) sel x
op safe2 x = |/ safe@ (iota rho x) @delete x
op solve2 x = +/ safe2@ x
solve sample
(Using the non-standard map operator-modifier '@' that I added to my copy in 2021. https://github.com/rsc/ivy)
=> More informations about this toot | More toots from rsc@hachyderm.io
Day 3 part 1.
The function 'c step s' steps the state machine state s to incorporate the new character c.
(step/ flip x) runs the state machine over the whole string, left to right.
The reduction base case for "...yz" is 'y' step 'z', which step rewrites to ('y' step 'z' step initial-state).
=> More informations about this toot | More toots from rsc@hachyderm.io
Day 3 part 2.
The function 'c step2 s' is the updated state machine, with an extra value tracking whether mul(x,y) is enabled. step2 takes care of do()/don't() processing and invokes 'step' (from part 1) to handle mul(x,y) when appropriate.
=> More informations about this toot | More toots from rsc@hachyderm.io
Day 4 part 1 https://adventofcode.com/2024/day/4 #AdventOfCode
pad dot-pads the matrix to avoid wraparound.
x y shift m rotates the matrix x left, y down.
d(=x y) shift4 m produces the 4 matrices shifted by d*0 1 2 3.
d XMAS m identifies the X in XMAS in direction d.
=> More informations about this toot | More toots from rsc@hachyderm.io
Day 4 part 2 #AdventOfCode
d shift3 m produces the 3 matrices shifted by d*-1 0 1.
d MAS m identifies the A in MAS in direction d.
d xMAS m identifies the A in MAS in direction d or -d.
xMAS m identifies the A in an X-MAS.
=> More informations about this toot | More toots from rsc@hachyderm.io
text/gemini
This content has been proxied by September (3851b).