Анаграми

Краен срок
14.11.2014 12:00

Срокът за предаване на решения е отминал

Анаграми

Описание на проблема

Анаграма наричаме дума, образувана чрез разбъркване на буквите на друга дума. Не добавяме нови букви, нито премахваме вече съществуващи.

Задачата ви е да създадете метода String#anagrams(words), който по подаден списък от думи връща само тези, които са анаграми на думата, върху която е извикан методът.

Резултатът от извикването на метода трябва да е енумератор, а ако е подаден блок - да yield-ва стойностите.

Примери

"world".anagrams(["wlord", "dwloor", "zombies", "word"]).to_a # => ["wlord"]
"Starer".anagrams(["cashregister", "Arrest", "stance"]).to_a # => ["Arrest"]
"world".anagrams(["wlord", "dwloor", "zombies", "word"]) { |anagram| puts anagram } # принтира "wlord" на стандартния изход

Ограничения

  • Никоя дума не е анаграма на себе си.
  • Методът трябва да работи с case insensitive вход.

Примерен тест

За информация как да изпълните примерния тест, погледнете GitHub хранилището с домашните.

Решения

Ясен Трифонов
  • Некоректно
  • 5 успешни тест(а)
  • 3 неуспешни тест(а)
Ясен Трифонов
class String
def anagrams(words)
return to_enum(:anagrams, words)
words.select do |word|
is_anagram = (word.upcase.chars.sort == upcase.chars.sort) && (word.upcase != upcase)
yield word if block_given? && is_anagram
is_anagram
end
end
end
.F..FF..

Failures:

  1) String#anagrams finds simple anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  ["tan"]
       actual collection contained:    []
       the missing elements were:      ["tan"]
     # /tmp/d20141114-26053-13ygkqy/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-13ygkqy/spec.rb:11:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams finds multiple anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  ["gallery", "largely", "regally"]
       actual collection contained:    []
       the missing elements were:      ["gallery", "largely", "regally"]
     # /tmp/d20141114-26053-13ygkqy/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-13ygkqy/spec.rb:23:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) String#anagrams finds case insensitive anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  ["Carthorse"]
       actual collection contained:    []
       the missing elements were:      ["Carthorse"]
     # /tmp/d20141114-26053-13ygkqy/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-13ygkqy/spec.rb:29:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00627 seconds
8 examples, 3 failures

Failed examples:

rspec /tmp/d20141114-26053-13ygkqy/spec.rb:10 # String#anagrams finds simple anagrams
rspec /tmp/d20141114-26053-13ygkqy/spec.rb:22 # String#anagrams finds multiple anagrams
rspec /tmp/d20141114-26053-13ygkqy/spec.rb:28 # String#anagrams finds case insensitive anagrams
Димитър Мутаров
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Мутаров
class String
def anagrams(words)
anagrams = words.select do |element|
formatted, self_formatted = element.downcase, self.downcase
(formatted != self_formatted) && (formatted.chars.sort == self_formatted.chars.sort)
end
return anagrams unless block_given?
yield anagrams
end
end
........

Finished in 0.00631 seconds
8 examples, 0 failures
Снежана Спасова
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Снежана Спасова
class String
def anagrams(words)
if block_given?
words.each { |word| yield word if word.downcase.chars.sort == downcase.chars.sort unless word == self }
else
words.select { |word| word.downcase.chars.sort == downcase.chars.sort unless word == self }
end
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-6ynxui/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-6ynxui/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00637 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-6ynxui/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Венцислав Димитров
  • Некоректно
  • 6 успешни тест(а)
  • 2 неуспешни тест(а)
Венцислав Димитров
class String
def anagrams(words)
sorted = self.downcase.chars.sort
result = words.select do |word|
word.downcase.chars.sort == sorted
end
if block_given?
result.each { |e| yield e }
else
result
end
end
end
......FF

Failures:

  1) String#anagrams does not return the receiver word because it is not anagram for itself
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["banana"]
       the extra elements were:        ["banana"]
     # /tmp/d20141114-26053-1ei6pr4/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1ei6pr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1ei6pr4/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1ei6pr4/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00646 seconds
8 examples, 2 failures

Failed examples:

rspec /tmp/d20141114-26053-1ei6pr4/spec.rb:33 # String#anagrams does not return the receiver word because it is not anagram for itself
rspec /tmp/d20141114-26053-1ei6pr4/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Камен Канев
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Камен Канев
class String
def anagrams(words, &block)
sorted = self.downcase.each_char.sort
words.select do |word|
self.downcase != word.downcase and sorted == word.downcase.each_char.sort
end.to_enum.each{ |word| yield word if block_given?}
end
end
........

Finished in 0.00641 seconds
8 examples, 0 failures
Людмила Савова
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Людмила Савова
class String
def anagrams(words)
result = []
words.each { |word|
if word.downcase.chars.sort.join == self.downcase.chars.sort.join and word != self
result << word
end }
result
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1p3llq6/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1p3llq6/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00649 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-1p3llq6/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Емилиан Станков
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Емилиан Станков
class String
def anagrams(words)
result = words.each_with_object([]) do |word, result|
if word.upcase.each_char.sort == self.upcase.each_char.sort
result << word if word.upcase != self.upcase
end
end
if block_given?
result.to_enum.each { |entry| yield entry}
else
result.to_enum
end
end
end
........

Finished in 0.00831 seconds
8 examples, 0 failures
Николай Димитров
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Димитров
class String
def anagrams(words, &block)
words.select { |word| casecmp(word) != 0 && upcase.chars.sort == word.upcase.chars.sort }.to_enum &block
end
end
........

Finished in 0.00627 seconds
8 examples, 0 failures
Александър Александров
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Александров
class String
def anagrams (words)
to_return = []
words.each do |variable|
to_return << variable if (self.upcase.chars.sort == variable.upcase.chars.sort and self.upcase != variable.upcase)
end
to_return = to_return.to_enum
if block_given?
to_return.each { |variable| yield(variable) }
else
to_return
end
end
end
........

Finished in 0.00672 seconds
8 examples, 0 failures
Константин Тодоров
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Тодоров
class String
def anagrams(words)
anagrams_array = []
words.each { |word| anagrams_array << word if word.anagram?(self.letters_to_hash) && word.downcase != self.downcase }
return anagrams_array.to_enum unless block_given?
anagrams_array.each { |anagram| yield anagram }
end
def letters_to_hash
letters = {}
self.downcase.chars.each do |letter|
letters[letter] = letters[letter].to_i + 1 # nil.to_i == 0
end
letters
end
def anagram?(letters)
return false if self.size == 0
self.downcase.chars.each do |letter|
return false if !letters[letter]
letters[letter] -= 1
end
letters.values.none? { |n| n != 0 }
end
end
........

Finished in 0.0066 seconds
8 examples, 0 failures
Бисер Кръстев
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Бисер Кръстев
class String
def anagrams(amongst)
return to_enum(:anagrams, amongst) unless block_given?
amongst.each { |word| yield word if is_anagram? word }
end
def is_anagram?(word)
downcase != word.downcase and downcase.chars.sort == word.downcase.chars.sort
end
end
........

Finished in 0.00626 seconds
8 examples, 0 failures
Габриела Лухова
  • Некоректно
  • 6 успешни тест(а)
  • 2 неуспешни тест(а)
Габриела Лухова
class String
def anagrams(words)
result = []
words.each do |word|
if self.histogram == word.histogram
if block_given?
yield word
else
result << word
end
end
end
result.to_enum
end
def histogram
counts = Hash.new(0)
self.downcase.each_char {|a| counts[a] += 1 }
counts
end
end
......FF

Failures:

  1) String#anagrams does not return the receiver word because it is not anagram for itself
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["banana"]
       the extra elements were:        ["banana"]
     # /tmp/d20141114-26053-1xq9a4j/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1xq9a4j/spec.rb:34:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1xq9a4j/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1xq9a4j/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00859 seconds
8 examples, 2 failures

Failed examples:

rspec /tmp/d20141114-26053-1xq9a4j/spec.rb:33 # String#anagrams does not return the receiver word because it is not anagram for itself
rspec /tmp/d20141114-26053-1xq9a4j/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Георги Костов
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Георги Костов
class String
def count_letters
count = Hash.new(0)
each_char { |letter| count[letter.downcase] += 1 }
count
end
def anagrams(words)
target = count_letters
a_list = (words - [self]).select { |word| word.count_letters == target }
result = Enumerator.new do |yielder|
a_list.each { |input| yielder << input }
end
if block_given?
loop do
yield result.next
end
else
result
end
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-skzhgp/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-skzhgp/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.20352 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-skzhgp/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Теодор Драганов
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Драганов
class String
def anagrams(words)
words.select do |word|
word.downcase.split("").sort == self.downcase.split("").sort &&
word.downcase != self.downcase
end
end
end
........

Finished in 0.0073 seconds
8 examples, 0 failures
Станислав Венков
  • Некоректно
  • 6 успешни тест(а)
  • 2 неуспешни тест(а)
Станислав Венков
class String
def anagrams(all_words)
anagrams_arr = []
all_words.each do |word|
if self.upcase.chars.sort == word.upcase.chars.sort
if block_given?
yield word
else
anagrams_arr << word
end
end
end
anagrams_arr unless block_given?
end
end
......FF

Failures:

  1) String#anagrams does not return the receiver word because it is not anagram for itself
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["banana"]
       the extra elements were:        ["banana"]
     # /tmp/d20141114-26053-1vgtr4s/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1vgtr4s/spec.rb:34:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1vgtr4s/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1vgtr4s/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00638 seconds
8 examples, 2 failures

Failed examples:

rspec /tmp/d20141114-26053-1vgtr4s/spec.rb:33 # String#anagrams does not return the receiver word because it is not anagram for itself
rspec /tmp/d20141114-26053-1vgtr4s/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Ангел Ангелов
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Ангел Ангелов
class String
def anagrams(words, &block)
words.select do |word|
downcase.chars.sort == word.downcase.chars.sort and word != self
end.each &block
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-13nfh78/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-13nfh78/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.22865 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-13nfh78/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Диана Генева
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Диана Генева
class String
def anagrams(words, &block)
anagrams = []
alphabetical = self.downcase.split('').sort.join
words.each do |word|
unless self == word
anagrams << word if word.downcase.split('').sort.join == alphabetical
end
end
anagrams.each(&block)
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1mc2vfu/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1mc2vfu/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00712 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-1mc2vfu/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Евгений Бояджиев
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Евгений Бояджиев
class String
def anagrams (words)
found_anagrams = []
self_letters_count = count_chars(self)
words.each do |word|
found_anagrams.push(word) if anagram?(word, self, self_letters_count)
end
return found_anagrams.to_enum unless block_given?
# else
yield found_anagrams
end
private
def count_chars(str)
chars_count = Hash.new
str.each_char do |ch|
sym = ch.downcase.to_sym
if chars_count[sym]
chars_count[sym] += 1
else
chars_count[sym] = 1
end
end
return chars_count
end
def anagram?(str, original_string, original_char_count)
return false if str == original_string
original_char_count.eql? count_chars(str)
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1be94zd/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1be94zd/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00825 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-1be94zd/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Мартина Радева
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Мартина Радева
class String
def absolute
self.downcase.chars.sort
end
def anagrams(words)
anagrams = []
words = words.delete_if {|word| word.downcase == self.downcase}
words.each { |word| anagrams << word if word.absolute == self.absolute}
block_given? ? yield(anagrams) : anagrams.to_enum
end
end
........

Finished in 0.00767 seconds
8 examples, 0 failures
Йоан Динков
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Йоан Динков
class String
def anagrams(array)
sorted = self.downcase.chars.sort
result = array.select {|word| word.downcase.chars.sort == sorted && word != self}
if (block_given?)
yield result
else
result
end
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1r0doig/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1r0doig/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00622 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-1r0doig/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Дамян Димитров
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Дамян Димитров
class String
def anagrams(words)
anagrams_list = words.find_all do |word|
word.downcase != downcase && word.downcase.chars.sort == downcase.chars.sort
end
return anagrams_list.to_enum unless block_given?
yield anagrams_list
end
end
........

Finished in 0.00627 seconds
8 examples, 0 failures
Веселин Добрев
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Веселин Добрев
class String
def anagrams(words = [])
if block_given?
words.each do |word|
if downcase.chars.sort == word.downcase.chars.sort && word.downcase != downcase
yield word
end
end
else
result = []
words.each do |word|
if downcase.chars.sort == word.downcase.chars.sort && word.downcase != downcase
result << word
end
end
result.to_enum
end
end
end
........

Finished in 0.00632 seconds
8 examples, 0 failures
Гюлджан Купен
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Гюлджан Купен
class String
def anagrams(words)
result = []
string = downcase.split(//)
words.each do |word|
if word.downcase.split(//) != string && word.downcase.split(//).sort == string.sort
result << word
end
end
if block_given?
result.each { |word| yield word }
else
result.to_enum
end
end
end
........

Finished in 0.00712 seconds
8 examples, 0 failures
Александър Пирнарев
  • Некоректно
  • 6 успешни тест(а)
  • 2 неуспешни тест(а)
Александър Пирнарев
class String
def anagrams(arr)
tempArray = Array.new
arr.each do |word|
tempArray << word if self.length == word.length
end
arr = []
tempArray.each do |word|
temp = word
arr << temp if self.downcase.split(//).sort == word.downcase.split(//).sort
end
arr.to_enum
if block_given?
arr.each { |word| yield word }
else return arr
end
end
end
......FF

Failures:

  1) String#anagrams does not return the receiver word because it is not anagram for itself
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["banana"]
       the extra elements were:        ["banana"]
     # /tmp/d20141114-26053-19elblb/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-19elblb/spec.rb:34:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-19elblb/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-19elblb/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00661 seconds
8 examples, 2 failures

Failed examples:

rspec /tmp/d20141114-26053-19elblb/spec.rb:33 # String#anagrams does not return the receiver word because it is not anagram for itself
rspec /tmp/d20141114-26053-19elblb/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Мария Дулева
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Дулева
class String
def anagrams(words)
result = ''
words.each do |word|
if word.downcase.chars.sort == self.downcase.chars.sort and word.downcase != self.downcase
result << word
result << ' '
end
end
result.split(' ')
end
end
........

Finished in 0.0062 seconds
8 examples, 0 failures
Светлозар Стефанов
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Светлозар Стефанов
class String
def anagrams(words)
temp = self.downcase.chars
res_array = []
words.each do |word|
res_array << word if word.downcase.is_anagram(temp)
end
if block_given?
res_array.each { |item| yield item }
else
res_array.to_enum
end
end
def is_anagram(char_array)
return false if self.chars.size != char_array.size || self.chars == char_array || self.empty?
self.chars.each do |letter|
char_array.slice!(char_array.index(letter)) if char_array.any? { |item| item == letter}
end
char_array.empty?
end
end
....F...

Failures:

  1) String#anagrams finds multiple anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  ["gallery", "largely", "regally"]
       actual collection contained:    ["gallery"]
       the missing elements were:      ["largely", "regally"]
     # /tmp/d20141114-26053-wwm1zv/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-wwm1zv/spec.rb:23:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00636 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-wwm1zv/spec.rb:22 # String#anagrams finds multiple anagrams
Деян Гюрджеклиев
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Гюрджеклиев
class String
def anagrams(words)
return to_enum(:anagrams, words) unless block_given?
sorted_chars(words)[downcase.chars.sort].each { |word| yield word unless casecmp(word) == 0 }
end
private
def sorted_chars(words)
words.each_with_object(Hash.new([])) do |word, hash|
hash[word.downcase.chars.sort] += [word]
end
end
end
........

Finished in 0.00713 seconds
8 examples, 0 failures
Йоана Тодорова
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Йоана Тодорова
class String
def anagrams(words, &block)
anagrams = words.select { |word| casecmp(word) != 0 && permutation_of?(word) }
return anagrams.to_enum(:each) unless block_given?
anagrams.each { |word| block.call(word) }
end
private
def permutation_of?(word)
downcase.chars.sort == word.downcase.chars.sort
end
end
........

Finished in 0.0063 seconds
8 examples, 0 failures
Александър Петков
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Петков
class String
def anagrams(words)
anagrams = words.select do |word|
word.downcase.chars.sort == self.downcase.chars.sort &&
word.downcase != self.downcase
end
if block_given?
anagrams.each { |anagram| yield anagram }
else
anagrams.to_enum
end
end
end
........

Finished in 0.00639 seconds
8 examples, 0 failures
Любомир Папазов
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Папазов
class String
def anagrams(words)
enumerator = words.select {|word| word.downcase != self.downcase}.group_by { |element| element.downcase.chars.sort }.select { |k, v| k == self.downcase.chars.sort }.values.flatten
end
end
........

Finished in 0.00887 seconds
8 examples, 0 failures
Тодор Табаков
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Тодор Табаков
class String
def anagrams(words)
anagrams = []
words.each do |word|
anagrams << word if word.downcase.chars.sort.join == self.downcase.chars.sort.join
end
anagrams.each do |word|
anagrams.delete(word) if word.downcase == self.downcase
end
if block_given?
anagrams.each {|word| yield(word)}
else
anagrams.to_enum
end
end
end
........

Finished in 0.00667 seconds
8 examples, 0 failures
Божидар Горов
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Горов
class String
def anagrams(words)
work_words = words.select { |word| anagram?(word) }
if block_given?
work_words.each { |word| yield word}
else
work_words.to_enum
end
end
private
def anagram?(word)
self.downcase.chars.sort.join == word.downcase.chars.sort.join &&
self.downcase != word.downcase
end
end
........

Finished in 0.00673 seconds
8 examples, 0 failures
Яни Малцев
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Яни Малцев
class String
def anagrams(array, &block)
ret_anagrams = []
array.each do |x|
ret_anagrams<<x if (x.downcase.chars.sort.join.eql? self.downcase.chars.sort.join) && !x.eql?(self)
end
ret_anagrams.each &block
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-17u7x58/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-17u7x58/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00652 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-17u7x58/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Камен Станев
  • Некоректно
  • 6 успешни тест(а)
  • 2 неуспешни тест(а)
Камен Станев
class String
def anagrams(word_list)
enum = word_list.select { |word| self.is_anagram_to?(word) }.to_enum
if block_given?
enum.each { |word| yield word }
end
enum
end
def is_anagram_to?(word)
self.downcase.chars.sort == word.downcase.chars.sort
end
end
......FF

Failures:

  1) String#anagrams does not return the receiver word because it is not anagram for itself
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["banana"]
       the extra elements were:        ["banana"]
     # /tmp/d20141114-26053-pvji6g/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-pvji6g/spec.rb:34:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-pvji6g/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-pvji6g/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00672 seconds
8 examples, 2 failures

Failed examples:

rspec /tmp/d20141114-26053-pvji6g/spec.rb:33 # String#anagrams does not return the receiver word because it is not anagram for itself
rspec /tmp/d20141114-26053-pvji6g/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Нели Василева
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Нели Василева
require 'set'
class String
def anagrams(words, &block)
result = Set.new
chars.permutation do |anagram|
words.each do |word|
if anagram.join.casecmp(word) == 0 && casecmp(anagram.join) != 0
result << word
end
end
end
result.each &block
end
end
.....F..

Failures:

  1) String#anagrams finds case insensitive anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
     Timeout::Error:
       execution expired
     # /tmp/d20141114-26053-1a4bg3g/solution.rb:7:in `block (2 levels) in anagrams'
     # /tmp/d20141114-26053-1a4bg3g/solution.rb:6:in `each'
     # /tmp/d20141114-26053-1a4bg3g/solution.rb:6:in `block in anagrams'
     # /tmp/d20141114-26053-1a4bg3g/solution.rb:5:in `permutation'
     # /tmp/d20141114-26053-1a4bg3g/solution.rb:5:in `anagrams'
     # /tmp/d20141114-26053-1a4bg3g/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1a4bg3g/spec.rb:29:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 1.11 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-1a4bg3g/spec.rb:28 # String#anagrams finds case insensitive anagrams
Елена Орешарова
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Елена Орешарова
class String
def anagrams(words)
words.select do |word|
(self.casecmp(word) != 0) &&
(self.upcase.chars.sort == word.upcase.chars.sort)
end.each do |word|
if block_given?
yield word
end
end.to_enum
end
end
........

Finished in 0.00631 seconds
8 examples, 0 failures
Любомир Петков
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Петков
class String
def anagrams(words)
all_possible_anagrams = self.downcase.chars.permutation(self.length).to_a
anagrams = words.select do |word|
word.downcase != self.downcase and
all_possible_anagrams.include? word.downcase.chars
end
if block_given?
yield anagrams
else
anagrams.each
end
end
end
........

Finished in 0.62587 seconds
8 examples, 0 failures
Ивайло Георгиев
  • Некоректно
  • 5 успешни тест(а)
  • 3 неуспешни тест(а)
Ивайло Георгиев
class String
def anagrams(words,&block)
anagrams_list = []
words.each{ |word| anagrams_list << word if self.downcase.chars.to_a.permutation.map(&:join).drop(1).include? word.downcase }
if block_given?
anagrams_list.each{ |word| yield word }
else
anagrams_list.to_enum
end
end
end
.....FFF

Failures:

  1) String#anagrams finds case insensitive anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
     Timeout::Error:
       execution expired
     # /tmp/d20141114-26053-1knuywa/solution.rb:4:in `permutation'
     # /tmp/d20141114-26053-1knuywa/solution.rb:4:in `each'
     # /tmp/d20141114-26053-1knuywa/solution.rb:4:in `map'
     # /tmp/d20141114-26053-1knuywa/solution.rb:4:in `block in anagrams'
     # /tmp/d20141114-26053-1knuywa/solution.rb:4:in `each'
     # /tmp/d20141114-26053-1knuywa/solution.rb:4:in `anagrams'
     # /tmp/d20141114-26053-1knuywa/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1knuywa/spec.rb:29:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams does not return the receiver word because it is not anagram for itself
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["banana"]
       the extra elements were:        ["banana"]
     # /tmp/d20141114-26053-1knuywa/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1knuywa/spec.rb:34:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1knuywa/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1knuywa/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 1.21 seconds
8 examples, 3 failures

Failed examples:

rspec /tmp/d20141114-26053-1knuywa/spec.rb:28 # String#anagrams finds case insensitive anagrams
rspec /tmp/d20141114-26053-1knuywa/spec.rb:33 # String#anagrams does not return the receiver word because it is not anagram for itself
rspec /tmp/d20141114-26053-1knuywa/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Екатерина Горанова
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Екатерина Горанова
class String
def anagrams(words)
words.select do |word|
downcase.chars.sort == word.downcase.chars.sort unless self.eql? word
end
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-fvtzk0/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-fvtzk0/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.0065 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-fvtzk0/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Светослав Кръстев
  • Некоректно
  • 6 успешни тест(а)
  • 2 неуспешни тест(а)
Светослав Кръстев
class String
def anagrams(words, &block)
self_packed = self.downcase.split("").group_by{ |x| x }.map{ |x,y| [x,y.size] }
result = []
words.each do |current|
current_packed = current.downcase.split("").group_by{ |x| x }.map{ |x,y| [x,y.size] }
if (self_packed - current_packed == []) && (not self_packed == current_packed)
result << current
end
end
if block_given?
result.each { |current| yield current }
else
result.to_enum(:each)
end
end
end
.F.F....

Failures:

  1) String#anagrams finds simple anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  ["tan"]
       actual collection contained:    ["stand", "tan"]
       the extra elements were:        ["stand"]
     # /tmp/d20141114-26053-xco9ho/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-xco9ho/spec.rb:11:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams eliminates anagram subsets
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["goody"]
       the extra elements were:        ["goody"]
     # /tmp/d20141114-26053-xco9ho/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-xco9ho/spec.rb:19:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.0089 seconds
8 examples, 2 failures

Failed examples:

rspec /tmp/d20141114-26053-xco9ho/spec.rb:10 # String#anagrams finds simple anagrams
rspec /tmp/d20141114-26053-xco9ho/spec.rb:18 # String#anagrams eliminates anagram subsets
Бетина Иванова
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Бетина Иванова
class String
def anagrams(words)
words = words - [self]
enum = words
.select { |item| downcase.chars.sort.join == item.downcase.chars.sort.join }
.to_enum
if block_given?
enum.each { |item| yield item }
else
enum
end
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-dbhdia/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-dbhdia/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00683 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-dbhdia/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Любомир Иванов
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Любомир Иванов
class String
def anagrams(word_array)
self_hash, result = Utils.hash_all_chars(self.downcase), []
word_array.each do | word |
result << word if ((self_hash == Utils.hash_all_chars(word.downcase)) && word != self)
end
if block_given?
yield result
else
result.to_enum
end
end
end
class Utils
def self.hash_all_chars string
result = {}
string.each_char do | char |
unless result[char]
result[char] = result[char].to_i
end
result[char] += 1
end
result
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1i2aiwp/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1i2aiwp/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00692 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-1i2aiwp/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Велислав Симеонов
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Велислав Симеонов
class String
def anagrams words
arr_words = []
words.each { |word| arr_words << word if ((word != self) && (isEqual word)) }
if block_given?
arr_words.each { |word| yield word}
else
arr_words.to_enum
end
end
def isEqual word
word.upcase.chars.sort.join == self.upcase.chars.sort.join
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-lj8396/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-lj8396/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.0066 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-lj8396/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Георги Павлов
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Георги Павлов
class String
def anagrams(words, &block)
anagrams = []
model = self.downcase.chars.permutation.map(&:join)
words.each do |word|
if model.include? word.downcase and self.downcase != word.downcase
anagrams << word
end
end
anagrams.each &block
end
end
.....F..

Failures:

  1) String#anagrams finds case insensitive anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
     Timeout::Error:
       execution expired
     # /tmp/d20141114-26053-15rwyv1/solution.rb:4:in `permutation'
     # /tmp/d20141114-26053-15rwyv1/solution.rb:4:in `each'
     # /tmp/d20141114-26053-15rwyv1/solution.rb:4:in `map'
     # /tmp/d20141114-26053-15rwyv1/solution.rb:4:in `anagrams'
     # /tmp/d20141114-26053-15rwyv1/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-15rwyv1/spec.rb:29:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 1.11 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-15rwyv1/spec.rb:28 # String#anagrams finds case insensitive anagrams
Атанас Цанков
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Цанков
class String
def anagrams(words, &block)
anagrams = []
words.each { |i| anagrams << i if self.downcase != i.downcase and self.downcase.chars.sort.join == i.downcase.chars.sort.join }
anagrams.each(&block)
end
end
........

Finished in 0.00646 seconds
8 examples, 0 failures
Кристиан Цветков
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиан Цветков
class String
def anagrams(words)
return to_enum(:anagrams, words) unless block_given?
result = Hash.new []
words.each_with_object(result) do |word, hash|
hash[word.downcase.chars.sort] += [word] if casecmp(word) != 0
end
result[self.downcase.chars.sort].each { |word| yield word }
end
end
........

Finished in 0.00692 seconds
8 examples, 0 failures
Светлозар Тодоров
  • Некоректно
  • 6 успешни тест(а)
  • 2 неуспешни тест(а)
Светлозар Тодоров
class String
def anagrams(words)
enumerator = words.select do |word|
word.histogram == self.histogram
end.to_enum
if block_given?
enumerator.each { |enumerator| yield enumerator }
else enumerator
end
end
def histogram
chars = {}
delete(' ').each_char do |char|
chars[char.downcase] = self.count(char)
end
chars
end
end
......FF

Failures:

  1) String#anagrams does not return the receiver word because it is not anagram for itself
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["banana"]
       the extra elements were:        ["banana"]
     # /tmp/d20141114-26053-1njj2gn/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1njj2gn/spec.rb:34:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1njj2gn/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1njj2gn/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00709 seconds
8 examples, 2 failures

Failed examples:

rspec /tmp/d20141114-26053-1njj2gn/spec.rb:33 # String#anagrams does not return the receiver word because it is not anagram for itself
rspec /tmp/d20141114-26053-1njj2gn/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Пламен Каращранов
  • Некоректно
  • 6 успешни тест(а)
  • 2 неуспешни тест(а)
Пламен Каращранов
class String
def anagrams( words )
temp = []
words.each do |word|
if self.dup.downcase.chars.sort.join == word.downcase.chars.sort.join
temp<<word
end
end
if block_given?
temp.each do |word|
yield word
end
else
temp.to_enum
end
end
end
......FF

Failures:

  1) String#anagrams does not return the receiver word because it is not anagram for itself
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["banana"]
       the extra elements were:        ["banana"]
     # /tmp/d20141114-26053-3nunt7/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-3nunt7/spec.rb:34:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-3nunt7/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-3nunt7/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00676 seconds
8 examples, 2 failures

Failed examples:

rspec /tmp/d20141114-26053-3nunt7/spec.rb:33 # String#anagrams does not return the receiver word because it is not anagram for itself
rspec /tmp/d20141114-26053-3nunt7/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Людмил Делчев
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Людмил Делчев
class String
def anagrams(words)
anagrams = words.select{|word| word.downcase.split(//).sort == downcase.split(//).sort}
anagrams = anagrams.select{|word| word.downcase != self.downcase}
if block_given?
anagrams.each{|anagram| yield anagram}
else
anagrams.each
end
end
end
........

Finished in 0.00682 seconds
8 examples, 0 failures
Станимир Митев
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Станимир Митев
class String
def anagrams(possible_anagrams)
anagrams = []
possible_anagrams.each do |word|
if self != word && delete(" ").downcase.split(//).sort == word.delete(" ").downcase.split(//).sort
anagrams.push(word)
end
end
unless block_given?
anagrams.to_enum
else
yield anagrams
end
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-yg0hq9/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-yg0hq9/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00712 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-yg0hq9/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Георги Димов
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Георги Димов
class String
def anagrams(words)
all_anagrams = self.downcase.chars.to_a.permutation.map(& :join)
valid_anagrams = []
words.each do |word|
valid_anagrams << word if all_anagrams.include? word.downcase and self.casecmp(word) != 0
end
valid_anagrams_enumerator = valid_anagrams.each
if block_given?
loop { yield valid_anagrams_enumerator.next }
else
valid_anagrams_enumerator
end
end
end
.....F..

Failures:

  1) String#anagrams finds case insensitive anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
     Timeout::Error:
       execution expired
     # /tmp/d20141114-26053-ve3mah/solution.rb:3:in `permutation'
     # /tmp/d20141114-26053-ve3mah/solution.rb:3:in `each'
     # /tmp/d20141114-26053-ve3mah/solution.rb:3:in `map'
     # /tmp/d20141114-26053-ve3mah/solution.rb:3:in `anagrams'
     # /tmp/d20141114-26053-ve3mah/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-ve3mah/spec.rb:29:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 1.11 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-ve3mah/spec.rb:28 # String#anagrams finds case insensitive anagrams
Атанас Димитров
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Атанас Димитров
class String
def anagrams(words)
block = Proc.new if block_given?
words.select { |word| is_anagram? word }.each(&block)
end
def is_anagram?(word)
casecmp(word) != 0 and downcase.chars.sort == word.downcase.chars.sort
end
end
........

Finished in 0.00677 seconds
8 examples, 0 failures
Любослава Димитрова
  • Некоректно
  • 6 успешни тест(а)
  • 2 неуспешни тест(а)
Любослава Димитрова
class String
def anagrams(words)
word = self.downcase.chars.sort
array = words.collect {|word| word.downcase.chars.sort}
result = []
array.each.with_index do |element, index|
if element == word and element != self.downcase
result << words[index]
end
end
return result.each unless block_given?
result.each {|element| yield element}
end
end
......FF

Failures:

  1) String#anagrams does not return the receiver word because it is not anagram for itself
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["banana"]
       the extra elements were:        ["banana"]
     # /tmp/d20141114-26053-l0bgo3/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-l0bgo3/spec.rb:34:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-l0bgo3/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-l0bgo3/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01666 seconds
8 examples, 2 failures

Failed examples:

rspec /tmp/d20141114-26053-l0bgo3/spec.rb:33 # String#anagrams does not return the receiver word because it is not anagram for itself
rspec /tmp/d20141114-26053-l0bgo3/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Калин Христов
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Калин Христов
class String
def anagrams(words)
our_word = downcase
anagrams = words.find_all { |word| anagrams_check(our_word, word) }
if block_given?
yield anagrams
else
anagrams
end
end
def anagrams_check(our_word, word_for_check)
our_word != word_for_check.downcase and
our_word.chars.to_a.sort == word_for_check.downcase.chars.to_a.sort
end
end
........

Finished in 0.0063 seconds
8 examples, 0 failures
Методи Димитров
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Методи Димитров
class String
def anagrams(words)
permutations = chars.permutation.map(&:join).map(&:downcase) - [downcase]
found_anagrams = words.lazy.select do |word|
permutations.include? word.downcase
end
found_anagrams.each { |anagram| yield anagram } if block_given?
found_anagrams
end
end
.....F..

Failures:

  1) String#anagrams finds case insensitive anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
     Timeout::Error:
       execution expired
     # /tmp/d20141114-26053-1uhxmg7/solution.rb:3:in `permutation'
     # /tmp/d20141114-26053-1uhxmg7/solution.rb:3:in `each'
     # /tmp/d20141114-26053-1uhxmg7/solution.rb:3:in `map'
     # /tmp/d20141114-26053-1uhxmg7/solution.rb:3:in `anagrams'
     # /tmp/d20141114-26053-1uhxmg7/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1uhxmg7/spec.rb:29:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 1.11 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-1uhxmg7/spec.rb:28 # String#anagrams finds case insensitive anagrams
Мая Терзиева
  • Коректно
  • 8 успешни тест(а)
  • 0 неуспешни тест(а)
Мая Терзиева
class String
def anagrams(words)
anagrams = words.select do |word|
(word.downcase != self.downcase) and
(word.downcase.split(//).sort == self.downcase.split(//).sort)
end
if block_given?
yield anagrams
else
anagrams.to_enum
end
end
end
........

Finished in 0.00677 seconds
8 examples, 0 failures
Йончо Йончев
  • Некоректно
  • 6 успешни тест(а)
  • 2 неуспешни тест(а)
Йончо Йончев
class String
def anagrams(words)
@words_hash = words.each_with_object(Hash.new []) do |word, hash|
hash[word.downcase.split('').sort.join] += [word]
end
return @words_hash[self.downcase.split('').sort.join]
end
end
......FF

Failures:

  1) String#anagrams does not return the receiver word because it is not anagram for itself
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["banana"]
       the extra elements were:        ["banana"]
     # /tmp/d20141114-26053-2231i1/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-2231i1/spec.rb:34:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-2231i1/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-2231i1/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00758 seconds
8 examples, 2 failures

Failed examples:

rspec /tmp/d20141114-26053-2231i1/spec.rb:33 # String#anagrams does not return the receiver word because it is not anagram for itself
rspec /tmp/d20141114-26053-2231i1/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case
Иван Кавалджиев
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Иван Кавалджиев
class String
def anagrams(words_list)
set = self.downcase.split(//).permutation.map { |member| member.join }
set = set.find_all { |member| member != self.downcase }
words_list.map { |word| word.downcase }
if block_given?
words_list.select { |word| yield word if set.include?(word.downcase)}
end
words_list.select { |word| set.include?(word.downcase) }.to_enum
end
end
.....F..

Failures:

  1) String#anagrams finds case insensitive anagrams
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
     Timeout::Error:
       execution expired
     # /tmp/d20141114-26053-ut1y2a/solution.rb:3:in `block in anagrams'
     # /tmp/d20141114-26053-ut1y2a/solution.rb:3:in `permutation'
     # /tmp/d20141114-26053-ut1y2a/solution.rb:3:in `each'
     # /tmp/d20141114-26053-ut1y2a/solution.rb:3:in `map'
     # /tmp/d20141114-26053-ut1y2a/solution.rb:3:in `anagrams'
     # /tmp/d20141114-26053-ut1y2a/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-ut1y2a/spec.rb:29:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 1.11 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-ut1y2a/spec.rb:28 # String#anagrams finds case insensitive anagrams
Герасим Станчев
  • Некоректно
  • 7 успешни тест(а)
  • 1 неуспешни тест(а)
Герасим Станчев
class String
def anagrams(words)
result = words.each_with_object([]) do |word, object|
if word.downcase.split('').sort == self.downcase.split('').sort and word != self
object << word
end
end
.to_enum
if block_given?
result.each { |word| yield word }
else
result
end
end
end
.......F

Failures:

  1) String#anagrams does not return the receiver word even if it is in different case
     Failure/Error: expect(word.anagrams(amongst).to_a).to match_array are
       expected collection contained:  []
       actual collection contained:    ["BANANA"]
       the extra elements were:        ["BANANA"]
     # /tmp/d20141114-26053-1nraip0/spec.rb:3:in `anagrams_for'
     # /tmp/d20141114-26053-1nraip0/spec.rb:38:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.00752 seconds
8 examples, 1 failure

Failed examples:

rspec /tmp/d20141114-26053-1nraip0/spec.rb:37 # String#anagrams does not return the receiver word even if it is in different case