aboutsummaryrefslogtreecommitdiff
path: root/2025/11
diff options
context:
space:
mode:
Diffstat (limited to '2025/11')
-rwxr-xr-x2025/11/puzzle-1.awk19
-rwxr-xr-x2025/11/puzzle-2.py37
2 files changed, 56 insertions, 0 deletions
diff --git a/2025/11/puzzle-1.awk b/2025/11/puzzle-1.awk
new file mode 100755
index 0000000..aa752e1
--- /dev/null
+++ b/2025/11/puzzle-1.awk
@@ -0,0 +1,19 @@
+#!/usr/bin/gawk -f
+
+function npaths(src, dst, n, i)
+{
+ if (src == dst)
+ return 1;
+ for (i in paths[src])
+ n += npaths(paths[src][i], dst)
+ return n
+}
+
+BEGIN { FS = ":? " }
+
+{
+ for (i = 2; i <= NF; i++)
+ paths[$1][i - 1] = $i
+}
+
+END { print npaths("you", "out") }
diff --git a/2025/11/puzzle-2.py b/2025/11/puzzle-2.py
new file mode 100755
index 0000000..629c10c
--- /dev/null
+++ b/2025/11/puzzle-2.py
@@ -0,0 +1,37 @@
+#!/usr/bin/python3
+
+import functools
+
+
+paths: dict[str, list[str]] = {}
+
+def main() -> None:
+ with open('input', 'r') as f:
+ for line in f.readlines():
+ x, *xs = line.split()
+ paths[x[:-1]] = xs
+
+ print(npaths('svr', 'out'))
+
+
+@functools.cache
+def npaths(
+ src: str,
+ dst: str,
+ dacp: bool = False,
+ fftp: bool = False,
+) -> bool | int:
+ return (
+ dacp and fftp
+ if src == dst else
+ sum(npaths(
+ nsrc,
+ dst,
+ dacp or src == 'dac',
+ fftp or src == 'fft',
+ ) for nsrc in paths[src])
+ )
+
+
+if __name__ == '__main__':
+ main()