Skip to content

Instantly share code, notes, and snippets.

@mcsf
Last active June 14, 2021 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcsf/bc88e20994468421c024567ff9c6b953 to your computer and use it in GitHub Desktop.
Save mcsf/bc88e20994468421c024567ff9c6b953 to your computer and use it in GitHub Desktop.
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