Skip to content

Instantly share code, notes, and snippets.

@niczky12
Created December 8, 2022 22:49
Show Gist options
  • Save niczky12/986a67f24b325c8f1bc678e628c55558 to your computer and use it in GitHub Desktop.
Save niczky12/986a67f24b325c8f1bc678e628c55558 to your computer and use it in GitHub Desktop.
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