Last active
December 6, 2019 19:06
-
-
Save rhowe/0fe4472811464f84d2b4d2f7a905d55f to your computer and use it in GitHub Desktop.
AOC2019day6part2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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