]> git.sommitrealweird.co.uk Git - advent-of-code-2021.git/blob - day02/sub.sh
b8040aa88129a3942fdf1275e4637a7cdbd36a48
[advent-of-code-2021.git] / day02 / sub.sh
1 #!/bin/bash
2
3 exec 3<input.txt
4 depth=0
5 horizontal=0
6 aim=0
7 aim_depth=0
8 aim_horizontal=0
9
10 while read -a things -u 3; do
11     case ${things[0]} in
12         up)
13             ((depth-=${things[1]}))
14             ((aim-=${things[1]}))
15             ;;
16         down)
17             ((depth+=${things[1]}))
18             ((aim+=${things[1]}))
19             ;;
20         forward)
21             ((horizontal+=${things[1]}))
22             depth_calc=$((things[1]*aim))
23             ((aim_depth+=$depth_calc))
24             ((aim_horizontal+=${things[1]}))
25             ;;
26     esac
27 done
28
29 echo "horz * depth = $((depth*$horizontal))"
30 echo "aimed version = $((aim_depth*$aim_horizontal))"