Skip to content

Instantly share code, notes, and snippets.

@rhowe
Last active December 6, 2019 19:06
Show Gist options
  • Save rhowe/0fe4472811464f84d2b4d2f7a905d55f to your computer and use it in GitHub Desktop.
Save rhowe/0fe4472811464f84d2b4d2f7a905d55f to your computer and use it in GitHub Desktop.
AOC2019day6part2
#!/bin/bash
set -eu
set -o pipefail
orrery=/dev/shm/orrery
rm -rf "$orrery"
mkdir "$orrery"
orbits=($(< "$1"))
for orbit in "${orbits[@]}"; do
inner=${orbit%)*}
outer=${orbit#*)}
innerdir=$(find "$orrery" -name "$inner")
outerdir=$(find "$orrery" -name "$outer")
if [ -z "$innerdir" ]; then
mkdir "$orrery/$inner"
innerdir=$orrery/$inner
fi
if [ -z "$outerdir" ]; then
mkdir "$innerdir/$outer"
else
mv "$outerdir" "$innerdir"/
fi
done
comm -3 <(find "$orrery" -name YOU -printf %P\\n|tr / \\n|sort) \
<(find "$orrery" -name SAN -printf %P\\n|tr / \\n|sort) \
| grep -cvE '^\s*(YOU|SAN)\s*$'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment