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 }