Solution to scrablle in Bash
This commit is contained in:
35
bash/scrabble-score/scrabble_score.sh
Normal file
35
bash/scrabble-score/scrabble_score.sh
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
score=0
|
||||
# converts the word to lowercase
|
||||
word=$(echo $1 | tr '[:upper:]' '[:lower:]')
|
||||
for (( i=0; i<${#word}; i++ )); do
|
||||
letter=${word:i:1}
|
||||
case $letter in
|
||||
[aeioulnrst])
|
||||
score=$((score+1))
|
||||
;;
|
||||
[dg])
|
||||
score=$((score+2))
|
||||
;;
|
||||
[bcmp])
|
||||
score=$((score+3))
|
||||
;;
|
||||
[fhvwy])
|
||||
score=$((score+4))
|
||||
;;
|
||||
[k])
|
||||
score=$((score+5))
|
||||
;;
|
||||
[jx])
|
||||
score=$((score+8))
|
||||
;;
|
||||
[qz])
|
||||
score=$((score+10))
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo $score
|
||||
Reference in New Issue
Block a user