Skip to content

Instantly share code, notes, and snippets.

Created May 21, 2014 17:51
Show Gist options
  • Save anonymous/5f42cddf1d90ba679249 to your computer and use it in GitHub Desktop.
Save anonymous/5f42cddf1d90ba679249 to your computer and use it in GitHub Desktop.
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
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"
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