day 2, parts 1 & 2

This commit is contained in:
setop 2021-12-02 09:09:35 +01:00
parent ec615662a4
commit 62275676a3
2 changed files with 10 additions and 5 deletions

View File

@ -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 }

5
d02/d02_2.awk Normal file
View File

@ -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 }