Created
April 15, 2013 06:06
-
-
Save robinsloan/5386022 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'numbers_and_words' | |
VOWELS = ['a','e','i','o','u'] | |
CONSONANTS = ('a'..'z').to_a.delete_if do |char| | |
VOWELS.include?(char) | |
end | |
def count(type,str) # type = VOWELS or CONSONANTS | |
str.downcase.split("").inject(0) do |count,char| | |
if type.include?(char) then | |
count + 1 | |
else | |
count | |
end | |
end | |
end | |
TweetCandidate = Struct.new(:vowels, :consonants, :text) | |
tweet_candidates = [] | |
50.times do |num_vowels| | |
50.times do |num_consonants| | |
tweet_candidates << TweetCandidate.new(num_vowels, num_consonants, "In this tweet are #{num_vowels.to_words.downcase} vowels and #{num_consonants.to_words.downcase} consonants") | |
end | |
end | |
tweet_candidates.each do |candidate| | |
if (count(VOWELS,candidate[:text]) == candidate[:vowels]) then | |
if (count(CONSONANTS,candidate[:text]) == candidate[:consonants]) then | |
puts "We have a winner!" | |
puts "=> #{candidate[:text]}" | |
end | |
end | |
end | |
# results: | |
# In this tweet are sixteen vowels and thirty consonants | |
# In this tweet are eighteen vowels and thirty-two consonants | |
# In this tweet are nineteen vowels and thirty-one consonants | |
# In this tweet are nineteen vowels and thirty-three consonants |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment