diff options
Diffstat (limited to 'day2/solution.sh')
| -rwxr-xr-x | day2/solution.sh | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/day2/solution.sh b/day2/solution.sh new file mode 100755 index 0000000..1b14538 --- /dev/null +++ b/day2/solution.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +field='roygbv' + +ops=$(cat input.txt) + +sorted_ops=$( + cat input.txt | + tr 'rvbgyo' '123456' | + grep -o . | + sort | + tr -d '\n' | + tr '123456' 'rvbgyo' +) + +calc() { + local ops=$1 + local pos=0 + for (( i=0; i<${#ops}; i++ )); do + ((pos++)) + while [ "${field:pos%${#field}:1}" != "${ops:i:1}" ]; do + ((pos++)) + done + done + echo $pos +} + +calc "$ops" +calc "$sorted_ops" |
