Day 8
This commit is contained in:
42
08/02.sh
Executable file
42
08/02.sh
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
sum=0
|
||||
while read line; do
|
||||
digits=' '$(sed -s 's/ | .*$//' <<< $line)' '
|
||||
number=( $(sed -e 's/.* | //' -e 's/ / /g' <<< $line) )
|
||||
decrypted_number=()
|
||||
digit_1=$(sed 's/^.* \([a-z]\{2\}\) .*$/\1/' <<< $digits)
|
||||
digit_4=$(sed 's/^.* \([a-z]\{4\}\) .*$/\1/' <<< $digits)
|
||||
digit_4_minus_1=$(sed -e "s/${digit_1:0:1}//" -e "s/${digit_1:1:1}//" <<< $digit_4)
|
||||
for i in ${number[@]}; do
|
||||
if [ ${#i} -eq 2 ]; then
|
||||
decrypted_number+=( 1 )
|
||||
elif [ ${#i} -eq 3 ]; then
|
||||
decrypted_number+=( 7 )
|
||||
elif [ ${#i} -eq 4 ]; then
|
||||
decrypted_number+=( 4 )
|
||||
elif [ ${#i} -eq 5 ]; then
|
||||
if [[ $i == *"${digit_1:0:1}"* ]] && [[ $i == *"${digit_1:1:1}"* ]]; then
|
||||
decrypted_number+=( 3 )
|
||||
elif [[ $i == *"${digit_4_minus_1:0:1}"* ]] && [[ $i == *"${digit_4_minus_1:1:1}"* ]]; then
|
||||
decrypted_number+=( 5 )
|
||||
else
|
||||
decrypted_number+=( 2 )
|
||||
fi
|
||||
elif [ ${#i} -eq 6 ]; then
|
||||
if [[ $i == *"${digit_4:0:1}"* ]] && [[ $i == *"${digit_4:1:1}"* ]] && \
|
||||
[[ $i == *"${digit_4:2:1}"* ]] && [[ $i == *"${digit_4:3:1}"* ]]; then
|
||||
decrypted_number+=( 9 )
|
||||
elif [[ $i == *"${digit_1:0:1}"* ]] && [[ $i == *"${digit_1:1:1}"* ]]; then
|
||||
decrypted_number+=( 0 )
|
||||
else
|
||||
decrypted_number+=( 6 )
|
||||
fi
|
||||
elif [ ${#i} -eq 7 ]; then
|
||||
decrypted_number+=( 8 )
|
||||
fi
|
||||
done
|
||||
temp_number=$(sed -e 's/ *//g' -e 's/^0*//' <<< "${decrypted_number[@]}")
|
||||
sum=$((sum+temp_number))
|
||||
done
|
||||
echo $sum
|
||||
Reference in New Issue
Block a user