Add day 25
Diff
2023/24.hs | 2 +-
2023/25.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
README | 3 +++
treefmt.nix | 3 +++
4 files changed, 59 insertions(+), 1 deletion(-)
@@ -4,7 +4,7 @@ import Aoc (readAndParseStdin)
import qualified Data.Map as Map
import Data.Maybe (fromJust, fromMaybe)
import Numeric.LinearAlgebra
import Text.Parsec (char, digit, many1, spaces, (<|>), sepBy, string)
import Text.Parsec (char, digit, many1, sepBy, spaces, string, (<|>))
import Text.Parsec.String (Parser)
main = do
@@ -0,0 +1,52 @@
set -euo pipefail
function log() {
echo -e "\033[34m$1\033[0m" >&2
}
function logc() {
echo -e "+ \033[35m$*\033[0m" >&2
"$@"
}
log "Generating graph visualisation using graphviz"
GRAPH=$(logc awk -F': ' '{split($2, nodes, " "); for (i in nodes) print $1" -- "nodes[i]}' input)
echo "graph a { $GRAPH }" | logc neato -Tpng | logc imgcat
while true; do
read -r -p "Which edge would you like to cut? (eg. AA -- BB) " ans
if [ "$ans" = "" ]; then
break
elif echo "$GRAPH" | grep -q "$ans"; then
GRAPH="${GRAPH//$ans/}"
echo "graph a { $GRAPH }" | logc neato -Tpng | logc imgcat
else
echo "No match for $ans"
fi
done
log "Calculating graph structure"
SPLIT=$(echo "graph a { $GRAPH }" | ccomps -x || true)
if [ "$(echo "$SPLIT" | grep -o "graph" | wc -l)" -ne 2 ]; then
echo "There's not two distinctive subgraphs, try again"
exit 1
fi
PART1=$(echo "$SPLIT" \
| logc awk '/^graph/ {subgraph=$2} /^[[:space:]]+/ {gsub(/;/, "", $1); gsub(/;/, "", $3); print subgraph, $1; print subgraph, $3}' \
| logc sort \
| logc uniq \
| logc cut -d ' ' -f 1 \
| logc uniq -c \
| tr '\n' ' ' \
| logc sed -E 's/^[[:space:]]+([0-9]+)[[:space:]]+[^ ]+[[:space:]]+([0-9]+).*/\1*\2\n/g' \
| bc)
echo "$PART1"
@@ -36,4 +36,7 @@
| 20 | Haskell |
| 21 | Rust |
| 22 | Haskell |
| 23 | Haskell |
| 24 | Haskell |
| 25 | Bash |
+---------------------+
@@ -10,5 +10,8 @@
rustfmt.enable = true;
fprettify.enable = true;
jsonnetfmt.enable = true;
shellcheck.enable = true;
};
settings.formatter.shellcheck.options = [ "-s" "bash" ];
}