Day 02 in awk
This commit is contained in:
parent
aaccc3c608
commit
1f78356cdb
|
@ -0,0 +1,6 @@
|
|||
forward 5
|
||||
down 5
|
||||
forward 8
|
||||
up 3
|
||||
down 8
|
||||
forward 2
|
|
@ -0,0 +1,8 @@
|
|||
BEGIN { FS=" " }
|
||||
|
||||
/forward/ { h_pos += $2 }
|
||||
/down/ { depth += $2 }
|
||||
/up/ { depth -= $2 }
|
||||
|
||||
END { print depth * h_pos }
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
BEGIN { FS=" " }
|
||||
|
||||
/down/ { aim += $2 }
|
||||
/up/ { aim -= $2 }
|
||||
/forward/ {
|
||||
h_pos += $2
|
||||
depth += aim * $2
|
||||
}
|
||||
|
||||
END { print depth * h_pos }
|
||||
|
Reference in New Issue