From 62275676a3cffbc4598627f68c6dea23cd06e081 Mon Sep 17 00:00:00 2001 From: setop Date: Thu, 2 Dec 2021 09:09:35 +0100 Subject: [PATCH] day 2, parts 1 & 2 --- d02/d02_1.awk | 10 +++++----- d02/d02_2.awk | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 d02/d02_2.awk diff --git a/d02/d02_1.awk b/d02/d02_1.awk index 177aae2..a2e3854 100644 --- a/d02/d02_1.awk +++ b/d02/d02_1.awk @@ -1,5 +1,5 @@ -BEGIN { h = 0; d = 0; a = 0; } -$1 == "forward" { h+=+$2; d+=+$2*a; } -$1 == "up" { a-=+$2 } -$1 == "down" { a+=+$2 } -END { print h*d } +BEGIN { h = 0; d = 0} +$1 == "forward" { h+=+$2 } +$1 == "up" { d-=+$2 } +$1 == "down" { d+=+$2 } +END { print h, d, h*d } diff --git a/d02/d02_2.awk b/d02/d02_2.awk new file mode 100644 index 0000000..177aae2 --- /dev/null +++ b/d02/d02_2.awk @@ -0,0 +1,5 @@ +BEGIN { h = 0; d = 0; a = 0; } +$1 == "forward" { h+=+$2; d+=+$2*a; } +$1 == "up" { a-=+$2 } +$1 == "down" { a+=+$2 } +END { print h*d }