-
Notifications
You must be signed in to change notification settings - Fork 0
/
part2.sh
executable file
·44 lines (40 loc) · 891 Bytes
/
part2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
file="./input.txt";
score=0;
member=0;
while read -r line; do
case $member in
0)
commonItems0=$line;
((member++));;
1)
unset commonItems1;
while read -n 1 char; do
if [[ "$commonItems0" == **"$char"** ]]; then
commonItems1+=$char;
fi
done <<< "$line"
((member++));;
2)
while read -n 1 char; do
if [[ "$commonItems1" == **"$char"** ]]; then
found=$(printf '%d' "'$char");
# a-z = 97-122
# A-Z = 65-90
if [ $found -le 90 ]; then
# uppercase
# -38=65-1-26
((found-=38));
else
# lowercase
# -96=97-1
((found-=96));
fi
((score+=found));
break;
fi
done <<< "$line"
member=0;;
esac
done < $file
echo "Answer: $score";