Skip to content

Instantly share code, notes, and snippets.

@bartolsthoorn
Created October 7, 2012 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartolsthoorn/b27ae8826d11b96cac40 to your computer and use it in GitHub Desktop.
Save bartolsthoorn/b27ae8826d11b96cac40 to your computer and use it in GitHub Desktop.
# Tests for string (WORD) gibberish
def gibberish_probability_fine(string)
# Calculate how many % of string is consonants
consonants = Common::CONSONANTS | Common::NUMBERS | ['-', '_']
fraction = string.downcase.count(consonants.join('').downcase).to_f/string.length.to_f
# fraction 0.0 - 1.0 turn into 1.0 - 0.0 - 1.0
# 0.0 => 1.0
# 0.5 => 0.0
# 1.0 => 1.0
fraction = (fraction-0.5).abs*2
return fraction
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment