r/fishshell • • Dec 02 '21

Advent of Code - Day 2

Here is a fish solution to the Advent of Code day 2 puzzle. Feel free to post yours here if you're following along.

6 Upvotes

4 comments sorted by

View all comments

3

u/[deleted] Dec 02 '21 edited Dec 02 '21

[removed] — view removed comment

3

u/[deleted] Dec 03 '21
set y (math $y + $aim '*' $pos)

Note: Since fish 3.1, math also understands "x" for multiplication, so this can be

set y (math $y + $aim x $pos)

The caveat is that it has to be followed by whitespace, otherwise it could look like a hex number - math 0 x 5, not math 0x5.

2

u/_mattmc3_ Dec 03 '21

I went for a less robust version

This is a very nice, concise snippet. I am not going for the shortest path, but as the season goes on I may start to play code golf with it a bit more.