Created
May 21, 2014 17:51
-
-
Save anonymous/5f42cddf1d90ba679249 to your computer and use it in GitHub Desktop.
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
it 'for "scream cars for four scar creams"' do | |
@anagrams = 'scream cars for four scar creams'.anagram_groups | |
@anagrams.each { |group| group.sort! } | |
[%w(cars scar), %w(four), %w(for), %w(creams scream)].each do |group| | |
@anagrams.should include(group) | |
end | |
end |
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
Failures: | |
1) anagram grouping for "scream cars for four scar creams" | |
Failure/Error: @anagrams.should include(group) | |
expected [] to include ["cars", "scar"] | |
# ./spec/fun_with_strings_spec.rb:56:in `block (3 levels) in <top (required)>' | |
# ./spec/fun_with_strings_spec.rb:55:in `each' | |
# ./spec/fun_with_strings_spec.rb:55:in `block (2 levels) in <top (required)>' | |
Finished in 0.00519 seconds | |
12 examples, 1 failure | |
Failed examples: | |
rspec ./spec/fun_with_strings_spec.rb:52 # anagram grouping for "scream cars for four scar creams" |
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
def anagram_groups | |
a=[] | |
a.map{|x| Array.new() << x << x.split('').shuffle.join << x.split('').shuffle.join << x.split('').shuffle.join << x.split('').shuffle.join << x.split('').shuffle.join << x.split('').shuffle.join << x.split('').shuffle.join << x.split('').shuffle.join << x.split('').shuffle.join} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment