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
@rsc
Edit -1, x/solve/a/2
=> More informations about this toot | More toots from oec@mathstodon.xyz
text/gemini
This content has been proxied by September (3851b).