Ancestors

Written by Russ Cox on 2024-12-02 at 15:34

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

Toot

Written by Russ Cox on 2024-12-02 at 15:35

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

Descendants

Written by Russ Cox on 2024-12-03 at 06:31

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).

=> View attached media

=> More informations about this toot | More toots from rsc@hachyderm.io

Written by Russ Cox on 2024-12-03 at 06:32

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.

=> View attached media

=> More informations about this toot | More toots from rsc@hachyderm.io

Written by Russ Cox on 2024-12-04 at 14:45

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.

=> View attached media

=> More informations about this toot | More toots from rsc@hachyderm.io

Written by Russ Cox on 2024-12-04 at 14:49

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.

=> View attached media

=> More informations about this toot | More toots from rsc@hachyderm.io

Written by Anisse on 2024-12-02 at 15:47

@rsc For a second, I thought it was https://microsoft.github.io/ivy/language.html , another language named Ivy, and first result for "Ivy language" here 😅

=> More informations about this toot | More toots from Aissen@treehouse.systems

Written by Özgür Kesim on 2024-12-02 at 19:36

@rsc

Edit -1, x/solve/a/2

=> More informations about this toot | More toots from oec@mathstodon.xyz

Written by kha on 2024-12-03 at 08:03

@rsc this is amazing

=> More informations about this toot | More toots from ntkha@mastodon.social

Written by Özgür Kesim on 2024-12-04 at 20:07

@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

Written by Russ Cox on 2024-12-04 at 23:45

@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

Written by Özgür Kesim on 2024-12-05 at 10:36

@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

Written by Tristan Colgate-McFarlane on 2024-12-27 at 14:33

@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

Proxy Information
Original URL
gemini://mastogem.picasoft.net/thread/113583960921083101
Status Code
Success (20)
Meta
text/gemini
Capsule Response Time
294.208032 milliseconds
Gemini-to-HTML Time
3.728769 milliseconds

This content has been proxied by September (3851b).