Go back

Day 01 (fish)

Not that hard, just needed to refresh my shell skills. :D

Code

cat 01.in | read -az INPUT

set occ
for i in (seq (math "max("(string join , $INPUT)")"))
    set -a occ 0
end

for id in $INPUT
    set occ[$id] (math $occ[$id] + 1)
end

echo "Part 1: "(math (for id in (seq (count $occ))
    echo "$occ[$id] $id"
end | sort -nr | head -n 3 | awk '{print $2}' | string join "*"))

echo "Part 2: "(math (for id in (seq (count $occ))
    if test $occ[$id] -gt 0
        echo "$occ[$id] $id"
    end
end | sort -n | head -n 3 | awk '{print $2}' | string join "*"))

© 2026 flowernal