Skip to content

Instantly share code, notes, and snippets.

@rhowe
Created December 6, 2019 18:49
Show Gist options
  • Save rhowe/001b5cac7cfa6bd7ac1eaf3cf66e72ed to your computer and use it in GitHub Desktop.
Save rhowe/001b5cac7cfa6bd7ac1eaf3cf66e72ed to your computer and use it in GitHub Desktop.
AOC2019day6part1
#!/bin/bash
set -eu
set -o pipefail
orrery=/dev/shm/orrery
cd "$(dirname "$0")"
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
( cd "$orrery" && find * -printf '%d\n' )|xargs|tr \ +|bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment