Last active
July 6, 2016 03:58
-
-
Save trevmex/3b4e3d70eda9832fe605e1d7803927e6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
words = File.readlines("/usr/share/dict/words").map(&:chomp).map(&:downcase) | |
words.reject! { |word| word.length > 7 } | |
line = ('a'..'z').to_a.sample(7) | |
puts line.join(", ") | |
perm = (1..7).inject([]) { |acc, n| | |
acc + line.permutation(n).to_a | |
} | |
joined = perm.inject([]) { |acc, word| | |
acc << word.join | |
} | |
list = joined.inject([]) { |acc, maybe_word| | |
if words.include?(maybe_word) | |
acc << maybe_word | |
else | |
acc | |
end | |
}.uniq | |
points = { | |
a:1, b:3, c:3, d:2, e:1, f:4, g:2, h:4, i:1, j:8, k:5, l:1, m:3, n:1, o:1, p:3, q:10, r:1, s:1, t:1, u:1, v:4, w:4, x:8, y:4, z:10 | |
} | |
puts list.inject([0, ""]) { |word_point, word| | |
point_value = word.split('').inject(0) { |acc, letter| acc += points[letter.to_sym] } | |
if point_value > word_point[0] | |
word_point[0] = point_value | |
word_point[1] = word | |
end | |
word_point | |
} | |
# 1 point: E ×12, A ×9, I ×9, O ×8, N ×6, R ×6, T ×6, L ×4, S ×4, U ×4 | |
# 2 points: D ×4, G ×3 | |
# 3 points: B ×2, C ×2, M ×2, P ×2 | |
# 4 points: F ×2, H ×2, V ×2, W ×2, Y ×2 | |
# 5 points: K ×1 | |
# 8 points: J ×1, X ×1 | |
# 10 points: Q ×1, Z ×1 | |
# 2 blank tiles (scoring 0 points) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment