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
@rsc this is amazing
=> More informations about this toot | More toots from ntkha@mastodon.social
@rsc Beautiful little machine! But alas, the first call to rho fails for me: it returns nothing on the scalar input so that the whole conditional doesn't parse correctly. Am I holding it wrong? (I had saved the input as ivy-strings, surrounded with ")
=> More informations about this toot | More toots from oec@mathstodon.xyz
@oec The input needs to be one very long string. I changed the \n to spaces when adding the quotation marks.
=> More informations about this toot | More toots from rsc@hachyderm.io
@rsc Yes, that is how my input looks, too. But I had to change (rho s) to (1 take rho s)[1] to make it work. Otherwise value/eval.go:/isTrue/ would choke on an unexpected Vector.
Do you maybe have unpublished changes to your copy of ivy?
=> More informations about this toot | More toots from oec@mathstodon.xyz
@oec @rsc the required bits are merged into upstream ivy now, with a slightly different flavour.
You can read the raw input from the downloaded data file (in day1) using:
sample = transp mix ivy@ sys "read" "input.txt"
=> More informations about this toot | More toots from tmcfarlane@toot.community This content has been proxied by September (3851b).Proxy Information
text/gemini