From 30fb572a31f7a71b7111a9e2645423ee49a09baa Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sun, 4 Dec 2022 16:06:46 +0100 Subject: Add 2022 day 4 solutions --- 2022/04/puzzles.awk | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 2022/04/puzzles.awk (limited to '2022/04/puzzles.awk') diff --git a/2022/04/puzzles.awk b/2022/04/puzzles.awk new file mode 100644 index 0000000..8ba715d --- /dev/null +++ b/2022/04/puzzles.awk @@ -0,0 +1,10 @@ +#!/usr/bin/awk -f + +BEGIN { FS = "[,-]" } +# START PART 1 +($1 <= $3 && $2 >= $4) || ($1 >= $3 && $2 <= $4) { c++ } +# END PART 1 START PART 2 +($3 >= $1 && $3 <= $2) || ($4 >= $1 && $4 <= $2) || + ($1 >= $3 && $1 <= $4) || ($2 >= $3 && $2 <= $4) { c++ } +# END PART 2 +END { print c } -- cgit v1.2.3