From 42e03dfbde7ec58c4d16cc671c3c2271b8d6d4c6 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Wed, 18 Dec 2024 21:59:32 +0100 Subject: Add 2019 day 6 solutions --- 2019/06/puzzle-1.awk | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 2019/06/puzzle-1.awk (limited to '2019/06/puzzle-1.awk') diff --git a/2019/06/puzzle-1.awk b/2019/06/puzzle-1.awk new file mode 100755 index 0000000..e694b4d --- /dev/null +++ b/2019/06/puzzle-1.awk @@ -0,0 +1,21 @@ +#!/usr/bin/awk -f + +function norbits(o) +{ + if (o in memo) + return memo[o] + return memo[o] = 1 + norbits(orbits[o]) +} + +BEGIN { + FS = ")" + memo["COM"] = 0 +} + +{ orbits[$2] = $1 } + +END { + for (o in orbits) + n += norbits(o) + print n +} \ No newline at end of file -- cgit v1.2.3