From 084205f6d798518e2f6d69eb9d8b2598ddc627b3 Mon Sep 17 00:00:00 2001 From: Pierre Jeanjean Date: Thu, 2 Dec 2021 10:49:38 +0100 Subject: [PATCH] Day 2 --- 02/01.sh | 18 ++++++++++++++++++ 02/02.sh | 20 ++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 02/01.sh create mode 100755 02/02.sh diff --git a/02/01.sh b/02/01.sh new file mode 100755 index 0000000..1f8ee3f --- /dev/null +++ b/02/01.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +depth=0 +horizontal=0 +while read current; do + if [[ "$current" == "down "* ]]; then + current_tmp=${current/down /} + depth=$((depth+current_tmp)) + elif [[ "$current" == "up "* ]]; then + current_tmp=${current/up /} + depth=$((depth-current_tmp)) + elif [[ "$current" == "forward "* ]]; then + current_tmp=${current/forward /} + horizontal=$((horizontal+current_tmp)) + fi +done + +echo $((depth*horizontal)) diff --git a/02/02.sh b/02/02.sh new file mode 100755 index 0000000..69e76d3 --- /dev/null +++ b/02/02.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +aim=0 +depth=0 +horizontal=0 +while read current; do + if [[ "$current" == "down "* ]]; then + current_tmp=${current/down /} + aim=$((aim+current_tmp)) + elif [[ "$current" == "up "* ]]; then + current_tmp=${current/up /} + aim=$((aim-current_tmp)) + elif [[ "$current" == "forward "* ]]; then + current_tmp=${current/forward /} + horizontal=$((horizontal+current_tmp)) + depth=$((depth+aim*current_tmp)) + fi +done + +echo $((depth*horizontal))