Created
December 8, 2022 22:49
-
-
Save niczky12/986a67f24b325c8f1bc678e628c55558 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
value_to_letters = Dict( | |
1 => ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'], | |
2 => ['D', 'G'], | |
3 => ['B', 'C', 'M', 'P'], | |
4 => ['F', 'H', 'V', 'W', 'Y'], | |
5 => ['K', ], | |
8 => ['J', 'X'], | |
10 => ['Q', 'Z'] | |
) | |
# reverse the dictionary to point from chars to ints | |
scores = Dict{Char, Int}() | |
for (value, letters) in value_to_letters | |
for letter in letters | |
scores[letter] = value | |
end | |
end | |
# function to calculate scores for each word/line | |
score(str) = mapreduce(letter -> get(scores, letter, 0), +, uppercase(str), init=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment