Намиране на брой общи цифри

Краен срок
23.10.2016 17:00

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

Намиране на брой общи цифри

Дефинирайте функция common_digits_count, която приема две цели числа и връща като резултат броя на цифрите, които се срещат както в едното, така и в другото число. Ако една цифра се среща по няколко пъти (както например 1 в 1111 и 121), я пребройте само веднъж.

Пример

common_digits_count(123444, 3445) # => 2
common_digits_count(456, -2358) # => 1

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

Написали сме примерни тестове, които може да намерите в хранилището с домашните.

Преди да предадете решение се уверете, че тестовете ви се изпълняват без грешки. Това ще ви гарантира, че не сте сбъркали нещо тривиално. Например име на функция, брой приемани аргументи и подобни.

Решения

Кирчо Кирев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Кирчо Кирев
def common_digits_count(first_number, second_number)
(first_number.abs.to_s.chars & second_number.abs.to_s.chars).count
end
...

Finished in 0.04737 seconds
3 examples, 0 failures
Милена Монова
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Милена Монова
def common_digits_count(first_digit, second_digit)
(first_digit.to_s.chars.map(&:to_i) & second_digit.to_s.chars.map(&:to_i)).size
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-1uk6h0n/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.0027 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-1uk6h0n/spec.rb:12 # #common_digits_count handles negative numbers
Здравко Петров
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Здравко Петров
def common_digits_count(num_one, num_two)
first_num = num_one.to_s.split('')
second_num = num_two.to_s.split('')
used_digits = [ ]
first_num.each do |digit_one|
second_num.each do |digit_two|
if digit_one == digit_two and !used_digits.include? digit_one
used_digits.push(digit_one)
end
end
end
used_digits.size
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-152ypc7/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00287 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-152ypc7/spec.rb:12 # #common_digits_count handles negative numbers
Христина Тодорова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Христина Тодорова
def common_digits_count(number1, number2)
(number1.abs.to_s.chars.uniq & number2.abs.to_s.chars.uniq).length
end
...

Finished in 0.00236 seconds
3 examples, 0 failures
Петко Митков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Петко Митков
def common_digits_count(first_num, second_num)
(first_num.abs.to_s.chars & second_num.abs.to_s.chars).size
end
...

Finished in 0.00231 seconds
3 examples, 0 failures
Красимир Тренчев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Красимир Тренчев
def common_digits_count(first, other)
unique_digits(first).count(unique_digits(other))
end
def unique_digits(number)
number.abs.to_s.chars.sort.join.squeeze
end
...

Finished in 0.00237 seconds
3 examples, 0 failures
София Петрова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
София Петрова
def common_digits_count(first_number, second_number)
first_number_uniq = (first_number.abs.to_s.split('')).uniq
second_number_uniq = (second_number.abs.to_s.split('')).uniq
numbers_count = (first_number_uniq + second_number_uniq).size
count_of_uniq_numbers = (first_number_uniq + second_number_uniq).uniq.size
numbers_count - count_of_uniq_numbers
end
...

Finished in 0.0025 seconds
3 examples, 0 failures
Даниела Русева
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Даниела Русева
def common_digits_count(first_number, second_number)
(first_number.to_s.split("") & second_number.to_s.split("")).size
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-138o79a/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00269 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-138o79a/spec.rb:12 # #common_digits_count handles negative numbers
Кузман Белев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Кузман Белев
def common_digits_count(number_one, number_two)
(convert_number(number_one) & convert_number(number_two)).count
end
def convert_number(number)
number.abs.to_s.each_char.to_a.uniq
end
...

Finished in 0.0024 seconds
3 examples, 0 failures
Исмаил Алиджиков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Исмаил Алиджиков
def common_digits_count(num_one, num_two)
array_one = num_one.abs.to_s.split('').map(&:to_i)
array_two = num_two.abs.to_s.split('').map(&:to_i)
(array_one.uniq & array_two).length
end
...

Finished in 0.00251 seconds
3 examples, 0 failures
Виктор Маринов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Виктор Маринов
def common_digits_count(first, second)
(get_digits(first) & get_digits(second)).size
end
def get_digits(number)
number.to_s.chars.map(&:to_i)
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-ldm4mj/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00238 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-ldm4mj/spec.rb:12 # #common_digits_count handles negative numbers
Калина Бухлева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Калина Бухлева
def common_digits_count(first_number, second_number)
first_number.abs.to_s.chars.select { |key| second_number.to_s.include? key }.uniq.count
end
...

Finished in 0.00228 seconds
3 examples, 0 failures
Виктор Клисуров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Клисуров
def common_digits_count(num1, num2)
a = num1.abs.to_s.split('').uniq
b = num2.abs.to_s.split('').uniq
result = 0
a.select { |num| result += 1 if b.include?(num) }.length
result
end
...

Finished in 0.00249 seconds
3 examples, 0 failures
Добрин Цветков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Добрин Цветков
def common_digits_count(first_number, second_number)
result = 0
('0'..'9').each do |digit|
if first_number.to_s.include?(digit) && second_number.to_s.include?(digit)
result += 1
end
end
result
end
...

Finished in 0.00237 seconds
3 examples, 0 failures
Христо Христов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Христов
def common_digits_count( num1, num2)
counter = 0
num1.to_s.delete('-').split('').uniq.each { |index| num2.to_s.split('').uniq.each { |index2| if ( index2 == index ) then counter+=1 end}}
counter
end
...

Finished in 0.0029 seconds
3 examples, 0 failures
Калоян Евтимов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Калоян Евтимов
def common_digits_count(first_dig, second_dig)
first_dig_unique = first_dig.abs.to_s.split(//).uniq
second_dig_unique = second_dig.abs.to_s.split(//).uniq
(first_dig_unique & second_dig_unique).length
end
...

Finished in 0.00246 seconds
3 examples, 0 failures
Петър Скорчелиев
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Петър Скорчелиев
def common_digits_count(first, second)
(first.to_s.chars & second.to_s.chars).size
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-163feru/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00236 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-163feru/spec.rb:12 # #common_digits_count handles negative numbers
Лазар Дилов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Лазар Дилов
def common_digits_count(x, y)
x = x.abs.to_s.chars.map { |x| x.to_i }
y = y.abs.to_s.chars.map { |x| x.to_i }
(x & y).size
end
...

Finished in 0.00235 seconds
3 examples, 0 failures
Теодор Филипов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Теодор Филипов
require 'set'
def common_digits_count(number1, number2)
number1.to_s.chars.map(&:to_i).to_set
.select(& -> (digit) { digit_is_in_number? digit, number2 }).count
end
def digit_is_in_number?(digit, number)
number.to_s.chars.map(&:to_i).include? digit
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-u98ja8/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00263 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-u98ja8/spec.rb:12 # #common_digits_count handles negative numbers
Николина Гюрова
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Николина Гюрова
def common_digits_count(first, second)
(first.to_s.split('') & second.to_s.split('')).length
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-srmap6/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00252 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-srmap6/spec.rb:12 # #common_digits_count handles negative numbers
Дарин Тодоров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Дарин Тодоров
def common_digits_count(first_number, second_number)
array_of_digits_fn = first_number.abs.to_s.split('')
array_of_digits_sn = second_number.abs.to_s.split('')
( array_of_digits_fn & array_of_digits_sn ).length
end
...

Finished in 0.00244 seconds
3 examples, 0 failures
Беатрис Бонева
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Беатрис Бонева
def common_digits_count(first, second) (first.to_s.split('') & second.to_s.split('')).count end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-8br753/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00252 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-8br753/spec.rb:12 # #common_digits_count handles negative numbers
Димитър Стефанов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Димитър Стефанов
def common_digits_count(number_one, number_two)
array_of_digits_one = number_one.to_s.split('')
array_of_digits_two = number_two.to_s.split('')
result_array = []
array_of_digits_one.each do |x|
result_array.push x if array_of_digits_two.include? x
array_of_digits_two.delete x
end
result_array.size
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-1jrblld/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00255 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-1jrblld/spec.rb:12 # #common_digits_count handles negative numbers
Ралица Дарджонова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Ралица Дарджонова
def common_digits_count(num1, num2)
(num1.abs.to_s.split(//).uniq & num2.abs.to_s.split(//).uniq).length
end
...

Finished in 0.00239 seconds
3 examples, 0 failures
Владимир Алексиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Владимир Алексиев
def common_digits_count(first, second)
(first.abs.to_s.split('') & second.abs.to_s.split('')).uniq.size
end
...

Finished in 0.00244 seconds
3 examples, 0 failures
Валентин Георгиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Валентин Георгиев
def common_digits_count(f_num, s_num)
f_num.to_s.scan(/\d/).uniq.find_all { |digit| s_num.to_s.split('').include?(digit) }.count
end
...

Finished in 0.00278 seconds
3 examples, 0 failures
Станислав Димитров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Станислав Димитров
def common_digits_count(first_digit, second_digit)
first_digit = first_digit.abs().to_s.split('')
second_digit = second_digit.abs().to_s.split('')
intersection = first_digit & second_digit
intersection.size()
end
...

Finished in 0.00244 seconds
3 examples, 0 failures
Мартин Христов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Мартин Христов
def common_digits_count(first_number, second_number)
first_number_uniq = first_number.to_s.chars.uniq
second_number_uniq = second_number.to_s.chars.uniq
(first_number_uniq & second_number_uniq).size
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-126et0m/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00241 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-126et0m/spec.rb:12 # #common_digits_count handles negative numbers
Петър Нетовски
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Нетовски
def common_digits_count(first_number, second_number)
(first_number.to_s.scan(/\d/).map { |digit| digit.to_i } & second_number.to_s.scan(/\d/).map { |digit| digit.to_i }).size
end
...

Finished in 0.00243 seconds
3 examples, 0 failures
Михаил Здравков
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Михаил Здравков
def common_digits_count(num1, num2)
common = num1.to_s.split('') & num2.to_s.split('')
common.count
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-n76bxr/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00273 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-n76bxr/spec.rb:12 # #common_digits_count handles negative numbers
Петър Велев
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Петър Велев
def common_digits_count(num1,num2)
num1.to_s.split('').unique.join.count(num2.to_s.split('').unique.join)
end
class Array
def unique
self & self
end
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-9d1udy/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00263 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-9d1udy/spec.rb:12 # #common_digits_count handles negative numbers
Костадин Самарджиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Костадин Самарджиев
def common_digits_count(number_one, number_two)
(number_one.abs.to_s.chars.map(&:to_i) &
number_two.abs.to_s.chars.map(&:to_i)).size
end
...

Finished in 0.00232 seconds
3 examples, 0 failures
Методи Димитров
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Методи Димитров
def common_digits_count(first_number, second_number)
(first_number.to_s.chars & second_number.to_s.chars).count
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-196fmvw/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00237 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-196fmvw/spec.rb:12 # #common_digits_count handles negative numbers
Елеонора Кайкова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Елеонора Кайкова
def common_digits_count(first_number, second_number)
first_string = first_number.to_s
second_string = second_number.to_s
count = 0
0.upto(9) do |n|
count += 1 if first_string.include?(n.to_s) &&
second_string.include?(n.to_s)
end
count
end
...

Finished in 0.00232 seconds
3 examples, 0 failures
Симеон Гергинов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Симеон Гергинов
def common_digits_count(first_number, second_number)
(first_number.to_s.chars.map(&:to_i) & second_number.to_s.chars.map(&:to_i)).count
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-cznf74/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00233 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-cznf74/spec.rb:12 # #common_digits_count handles negative numbers
Георги Иванов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Иванов
def digits (number)
number.abs.to_s.split('')
end
def common_digits_count (num1, num2)
(digits(num1) & digits(num2)).length
end
...

Finished in 0.00241 seconds
3 examples, 0 failures
Натали Арабаджийска
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Натали Арабаджийска
def common_digits_count (one, two)
one = one.to_s.split("")
two = two.to_s.split("")
one.uniq!
two.uniq!
count = 0
one.map do |num|
two.map do |num2|
if num == num2
count += 1
end
end
end
count
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-1sle5p1/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00258 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-1sle5p1/spec.rb:12 # #common_digits_count handles negative numbers
Цветан Христов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Христов
def common_digits_count(first_number, second_number)
first_number.abs.to_s.chars.select do |n|
second_number.abs.to_s.chars.include? n
end.uniq.count
end
...

Finished in 0.0024 seconds
3 examples, 0 failures
Никола Жишев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Жишев
def common_digits_count(a, b)
[a, b].map { |x| x.abs.to_s.split('').uniq }.reduce(:&).count
end
...

Finished in 0.00256 seconds
3 examples, 0 failures
Стамен Драгоев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Стамен Драгоев
def common_digits_count(number_one, number_two)
count = 0
10.times do |i|
bool_one = number_one.to_s.include? i.to_s
bool_two = number_two.to_s.include? i.to_s
count += 1 if bool_one && bool_two
end
count
end
...

Finished in 0.00238 seconds
3 examples, 0 failures
Ивайло Дончев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Ивайло Дончев
def common_digits_count(f_number, s_number)
# get intersection of splitted stringified numbers by '' and remove '-' sign
((f_number.to_s.split('') & s_number.to_s.split('')) - ['-']).length
end
...

Finished in 0.00252 seconds
3 examples, 0 failures
Александър Илиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Илиев
def common_digits_count(first, second)
common_chars = (first.to_s.split('') & second.to_s.split(''))
common_chars.delete("-")
common_chars.size
end
...

Finished in 0.00242 seconds
3 examples, 0 failures
Мая Терзиева
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Мая Терзиева
def common_digits_count(a, b)
(a.to_s.chars & b.to_s.chars).uniq.count
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-1gc8825/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00233 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-1gc8825/spec.rb:12 # #common_digits_count handles negative numbers
Мила Бянкова
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Мила Бянкова
require 'set'
def common_digits_count(first_number, second_number)
(first_number.to_s.chars.to_set & second_number.to_s.chars.to_set).count
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-1u2idus/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00257 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-1u2idus/spec.rb:12 # #common_digits_count handles negative numbers
Георги Карапетров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Карапетров
def array_of_digits(number)
number.abs.to_s.split('').map(&:to_i)
end
def common_digits_count(first, second)
digits_of_first = array_of_digits(first)
digits_of_second = array_of_digits(second)
common_digits = digits_of_first & digits_of_second
common_digits.uniq.count
end
...

Finished in 0.00251 seconds
3 examples, 0 failures
Богомила Пенева
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Богомила Пенева
def common_digits_count(num_one , num_two)
num_one = num_one.to_s.chars.map(&:to_i)
num_two = num_two.to_s.chars.map(&:to_i)
(num_one & num_two).length
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-14hwhrq/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00234 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-14hwhrq/spec.rb:12 # #common_digits_count handles negative numbers
Малина Демирова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Малина Демирова
def common_digits_count(first_number, second_number)
count = 0
prime_digits = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
prime_digits.each do |prime_digit|
(first_number.to_s.include? prime_digit) & (second_number.to_s.include? prime_digit) ? count += 1 : count
end
count
end
...

Finished in 0.0024 seconds
3 examples, 0 failures
Йордан Иванов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Йордан Иванов
def common_digits_count(first_num, second_num)
first_num = first_num.abs.to_s.chars.uniq
second_num = second_num.abs.to_s.chars.uniq
common_digits = 0
first_num.each do |digit_first|
second_num.each do |digit_second|
common_digits += 1 if digit_first == digit_second
end
end
common_digits
end
...

Finished in 0.00237 seconds
3 examples, 0 failures
Константин Нецов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Константин Нецов
def common_digits_count(num1, num2)
(num1.to_s.split("") & num2.to_s.split("")).size
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-m0ebo1/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00253 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-m0ebo1/spec.rb:12 # #common_digits_count handles negative numbers
Иво Яков
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Иво Яков
def common_digits_count(a, b)
(a.to_s.split('') & b.to_s.split('')).count
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-177llf6/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00256 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-177llf6/spec.rb:12 # #common_digits_count handles negative numbers
Момчил Баталов
  • Некоректно
  • 0 успешни тест(а)
  • 3 неуспешни тест(а)
Момчил Баталов
def common_digits_count(fnum, snum)
while(snum > 0)
puts fnum.to_s.scan("#{snum%10}")
snum /= 10
end
end
1
2
3
F2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
FF

Failures:

  1) #common_digits_count works for the simple cases
     Failure/Error: expect(common_digits_count(123, 321)).to eq 3
       
       expected: 3
            got: nil
       
       (compared using ==)
     # /tmp/d20161023-13689-13c97oe/spec.rb:3:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #common_digits_count avoids counting the same digit twice
     Failure/Error: expect(common_digits_count(121212, 1111222234)).to eq 2
       
       expected: 2
            got: nil
       
       (compared using ==)
     # /tmp/d20161023-13689-13c97oe/spec.rb:8:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  3) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: nil
       
       (compared using ==)
     # /tmp/d20161023-13689-13c97oe/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00273 seconds
3 examples, 3 failures

Failed examples:

rspec /tmp/d20161023-13689-13c97oe/spec.rb:2 # #common_digits_count works for the simple cases
rspec /tmp/d20161023-13689-13c97oe/spec.rb:7 # #common_digits_count avoids counting the same digit twice
rspec /tmp/d20161023-13689-13c97oe/spec.rb:12 # #common_digits_count handles negative numbers
Божидар Михайлов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Михайлов
def common_digits_count(n1, n2)
digits = -> (n) { n.abs.to_s.chars }
(digits.call(n1) & digits.call(n2)).length
end
...

Finished in 0.00232 seconds
3 examples, 0 failures
Мариян Асенов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Мариян Асенов
def common_digits_count(first_number, second_number)
digits_of_first_number = first_number.to_s.split("").delete_if { |x| x == "-" }.uniq
digits_of_second_number = second_number.to_s.split("").delete_if { |x| x == "-" }.uniq
digits_of_first_number.select { |item| digits_of_second_number.include?(item) }.size
end
...

Finished in 0.00258 seconds
3 examples, 0 failures
Радослав Гайдаров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Радослав Гайдаров
def common_digits_count(first, second)
first = first.abs.to_s.split('').map { |x| x.to_i }
second = second.abs.to_s.split('').map { |x| x.to_i }
(first & second).length
end
...

Finished in 0.00249 seconds
3 examples, 0 failures
Антон Сотиров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Антон Сотиров
def digits_of_number(list, number)
until number == 0
list.push(number % 10)
number /= 10
end
end
def common_digits_count(first, second)
hash = {}
(0..9).each do |x|
hash[x] = false
end
first *= -1 if first < 0
second *= -1 if second < 0
digits_first = []
digits_of_number(digits_first, first)
digits_second = []
digits_of_number(digits_second, second)
digits_first.each do |x|
digits_second.each do |y|
hash[x] = true if x == y
end
end
counter = 0
hash.each do |key, _|
counter += 1 if hash[key] == true
end
p counter
end
3
0
.2
4
.1
3
.

Finished in 0.00248 seconds
3 examples, 0 failures
Христо Кирилов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Кирилов
def common_digits_count(first, second)
first.abs.to_s.scan(/./).uniq.select { |i| second.to_s.include? i }.count
end
...

Finished in 0.00233 seconds
3 examples, 0 failures
Стоян Томицин
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Стоян Томицин
def common_digits_count( x, y )
x = x.to_s.chars.map( &:to_i )
y = y.to_s.chars.map( &:to_i )
z = x & y
z.length
end
..F

Failures:

  1) #common_digits_count handles negative numbers
     Failure/Error: expect(common_digits_count(-887, -188889)).to eq 1
       
       expected: 1
            got: 2
       
       (compared using ==)
     # /tmp/d20161023-13689-1slkau6/spec.rb:13:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00245 seconds
3 examples, 1 failure

Failed examples:

rspec /tmp/d20161023-13689-1slkau6/spec.rb:12 # #common_digits_count handles negative numbers
Константин Димитров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Димитров
def common_digits_count(first,second)
first_array=[]
first.to_s.each_char{|char| first_array<<char}
second_array=[]
second.to_s.each_char{|char| second_array<<char}
((first_array&second_array)-['-']).length
end
...

Finished in 0.0023 seconds
3 examples, 0 failures
Светослав Годжев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Светослав Годжев
def common_digits_count(number1, number2)
digit_count = {
1 => false,
2 => false,
3 => false,
4 => false,
5 => false,
6 => false,
7 => false,
8 => false,
9 => false,
0 => false
}
array1 = number1.abs.to_s.chars.map(&:to_i)
array2 = number2.abs.to_s.chars.map(&:to_i)
array1.each do |d1|
array2.each do |d2|
if d1 == d2
digit_count [d1] = true
break
end
end
end
count = 0
digit_count.each do |_k, value|
value ? count += 1 : next
end
count
end
...

Finished in 0.00234 seconds
3 examples, 0 failures
Васил Чимев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Васил Чимев
def common_digits_count(i, j)
r = 0
f = i.to_s.gsub('-', '').chars.uniq
s = j.to_s.gsub('-', '').chars.uniq
f.each { |k| (s.include? k) == true ? r += 1 : r }
r
end
...

Finished in 0.00278 seconds
3 examples, 0 failures
Сияна Плачкова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Сияна Плачкова
def common_digits_count(first_number, second_number)
(first_number.abs.to_s.chars & second_number.abs.to_s.chars).length
end
...

Finished in 0.0023 seconds
3 examples, 0 failures