- Коректно
- 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
Срокът за предаване на решения е отминал
Дефинирайте функция common_digits_count
, която приема две цели числа
и връща като резултат броя на цифрите, които се срещат както в едното, така и в другото число.
Ако една цифра се среща по няколко пъти (както например 1
в 1111
и 121
), я пребройте само веднъж.
common_digits_count(123444, 3445) # => 2
common_digits_count(456, -2358) # => 1
Написали сме примерни тестове, които може да намерите в хранилището с домашните.
Преди да предадете решение се уверете, че тестовете ви се изпълняват без грешки. Това ще ви гарантира, че не сте сбъркали нещо тривиално. Например име на функция, брой приемани аргументи и подобни.
... Finished in 0.04737 seconds 3 examples, 0 failures
..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
..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
... Finished in 0.00236 seconds 3 examples, 0 failures
... Finished in 0.00231 seconds 3 examples, 0 failures
... Finished in 0.00237 seconds 3 examples, 0 failures
... Finished in 0.0025 seconds 3 examples, 0 failures
..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
... Finished in 0.0024 seconds 3 examples, 0 failures
... Finished in 0.00251 seconds 3 examples, 0 failures
..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
... Finished in 0.00228 seconds 3 examples, 0 failures
... Finished in 0.00249 seconds 3 examples, 0 failures
... Finished in 0.00237 seconds 3 examples, 0 failures
... Finished in 0.0029 seconds 3 examples, 0 failures
... Finished in 0.00246 seconds 3 examples, 0 failures
..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
... Finished in 0.00235 seconds 3 examples, 0 failures
..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
..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
... Finished in 0.00244 seconds 3 examples, 0 failures
..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
..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
... Finished in 0.00239 seconds 3 examples, 0 failures
... Finished in 0.00244 seconds 3 examples, 0 failures
... Finished in 0.00278 seconds 3 examples, 0 failures
... Finished in 0.00244 seconds 3 examples, 0 failures
..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
... Finished in 0.00243 seconds 3 examples, 0 failures
..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
..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
... Finished in 0.00232 seconds 3 examples, 0 failures
..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
... Finished in 0.00232 seconds 3 examples, 0 failures
..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
... Finished in 0.00241 seconds 3 examples, 0 failures
..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
... Finished in 0.0024 seconds 3 examples, 0 failures
... Finished in 0.00256 seconds 3 examples, 0 failures
... Finished in 0.00238 seconds 3 examples, 0 failures
... Finished in 0.00252 seconds 3 examples, 0 failures
... Finished in 0.00242 seconds 3 examples, 0 failures
..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
..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
... Finished in 0.00251 seconds 3 examples, 0 failures
..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
... Finished in 0.0024 seconds 3 examples, 0 failures
... Finished in 0.00237 seconds 3 examples, 0 failures
..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
..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
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
... Finished in 0.00232 seconds 3 examples, 0 failures
... Finished in 0.00258 seconds 3 examples, 0 failures
... Finished in 0.00249 seconds 3 examples, 0 failures
3 0 .2 4 .1 3 . Finished in 0.00248 seconds 3 examples, 0 failures
... Finished in 0.00233 seconds 3 examples, 0 failures
..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
... Finished in 0.0023 seconds 3 examples, 0 failures
... Finished in 0.00234 seconds 3 examples, 0 failures
... Finished in 0.00278 seconds 3 examples, 0 failures
... Finished in 0.0023 seconds 3 examples, 0 failures