Created
January 22, 2011 21:45
-
-
Save aarongreenlee/791513 to your computer and use it in GitHub Desktop.
Learning Ruby!
This file contains 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
# Aaron Greenlee | |
# http://aarongreenlee.com/ | |
# Activity 2.1: Warmup 3 | |
puts "Give me three sets of words like 'apples and oranges' and 'are good to eat'" | |
puts "You'll then see every combination between the two groups." | |
word_groups = { :one => [],:two => [],:three => [] } | |
word_groups.each { |k,v| | |
puts "What words for group #{k}? : " | |
word_groups[k] = gets.chomp.strip.downcase.split(' ').uniq | |
} | |
puts '\nCool! Here are the combinations between groups...\n' | |
combos = [] | |
word_groups.each { |outer_group,prefixes| | |
prefixes.each { |prefix| | |
word_groups.each { |inner_group,suffixes| | |
if outer_group != inner_group | |
suffixes.each { |suffix| | |
if prefix != suffix | |
combos << prefix + suffix | |
end | |
} | |
end | |
} | |
} | |
} | |
puts "\nAnd the combinations are....\n\n" | |
combos.each { |w| puts w } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment