Skip to content

Instantly share code, notes, and snippets.

@stevedev
Created December 14, 2018 18:00
Show Gist options
  • Save stevedev/f307b3dbf6fd9fdc1214131a5bf9e6b0 to your computer and use it in GitHub Desktop.
Save stevedev/f307b3dbf6fd9fdc1214131a5bf9e6b0 to your computer and use it in GitHub Desktop.
Scrabble for slack...
#!/usr/bin/env ruby
VALUES = [
[1, %w{ e a o t i n r }],
[2, %w{ d g }],
[3, %w{ c m b p }],
[4, %w{ h f w y v }],
[5, %w{ k }],
[8, %w{ h x }],
[10, %w{ q z }]
]
exceptions = {
"a" => "a2",
"b" => "b2",
"h" => "h2",
"m" => "m2",
"o" => "o3",
"q" => "q2",
"v" => "v2",
"x" => "x2",
" " => "blank2"
}
str = ARGV.join " "
str.downcase!
output = ""
total_value = 0
def find_value(letter)
VALUES.each do |points, letters|
if letters.include? letter
return points
end
end
0
end
str.chars.each do |char|
next if char.match(/[^a-z\s_]/)
total_value += find_value(char)
if exceptions.include? char
output << ":#{exceptions[char]}:"
else
output << ":#{char}:"
end
end
puts "#{output} (#{total_value} points)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment