diff options
Diffstat (limited to '2024/07/puzzles.awk')
-rw-r--r-- | 2024/07/puzzles.awk | 19 |
1 files changed, 19 insertions, 0 deletions
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 |