Day 02 in awk

This commit is contained in:
aru 2021-12-02 10:01:01 +01:00
parent aaccc3c608
commit 1f78356cdb
3 changed files with 25 additions and 0 deletions

6
02/example_input Normal file
View File

@ -0,0 +1,6 @@
forward 5
down 5
forward 8
up 3
down 8
forward 2

8
02/solution-part1.awk Normal file
View File

@ -0,0 +1,8 @@
BEGIN { FS=" " }
/forward/ { h_pos += $2 }
/down/ { depth += $2 }
/up/ { depth -= $2 }
END { print depth * h_pos }

11
02/solution-part2.awk Normal file
View File

@ -0,0 +1,11 @@
BEGIN { FS=" " }
/down/ { aim += $2 }
/up/ { aim -= $2 }
/forward/ {
h_pos += $2
depth += aim * $2
}
END { print depth * h_pos }