Skip to content

Instantly share code, notes, and snippets.

@mcsf
Last active Jun 14, 2021
Embed
What would you like to do?
Awkward Advent of Code solutions (2019, day 6)
#!/bin/bash
chain() {
awk -F')' '
{ printf "%s: %s\n\t# %s\n", $2, $1, $2 }
END { print "COM:" }
' | make -f- "$1"
}
checksums() {
objs=$(cut -d')' -f2 "$1" | grep -Ev 'COM|SAN|YOU')
for o in $objs; do chain "$o" <"$1"; done | wc -l
}
transfers() {
comm -3 <(chain YOU <"$1") <(chain SAN <"$1") \
| awk 'END { print NR - 2 }' # Subtract YOU and SAN
}
checksums "$1"
transfers "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment