From db863f2beb82a5da9ec6d4fabda498756422ad7a Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 7 Dec 2024 13:28:12 +0100 Subject: Add 2024 day 7 solutions --- 2024/07/puzzles.awk | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 2024/07/puzzles.awk (limited to '2024/07/puzzles.awk') diff --git a/2024/07/puzzles.awk b/2024/07/puzzles.awk new file mode 100644 index 0000000..75564e8 --- /dev/null +++ b/2024/07/puzzles.awk @@ -0,0 +1,19 @@ +#!/usr/bin/gawk -f + +function eval(i, acc) +{ + if (acc > $1) + return 0 + if (i == NF + 1) + return acc == $1 +# START PART 1 + return eval(i + 1, acc * $i) || eval(i + 1, acc + $i) +# END PART 1 START PART 2 + return eval(i + 1, (acc $i) + 0) || eval(i + 1, acc * $i) || + eval(i + 1, acc + $i) +# END PART 2 +} + +BEGIN { FS = ":? " } +eval(3, $2) { n += $1 } +END { print n } \ No newline at end of file -- cgit v1.2.3