- Коректно
- 4 успешни тест(а)
- 0 неуспешни тест(а)
def fibonacci_like?(list)
list.each_cons(3).all? { |a, b, c| a + b == c }
end
.... Finished in 0.00276 seconds 4 examples, 0 failures
Срокът за предаване на решения е отминал
Дефинирайте функция fibonacci_like?
, която приема списък от числа и проверява дали
подадената редица "прилича" на фибоначи, т.е. всеки неин член е получен от сумата на
предишните два. Нека върнатият резултат е true
или false
в зависимост от това дали
условието е изпълнено или не. Ще подаваме редици с поне 3 числа.
fibonacci_like?([2, 6, 8, 14, 22, 36]) # => true
fibonacci_like?([0, 1, 1, 2, 3, 8]) # => false
Написали сме примерни тестове, които може да намерите в хранилището с домашните.
Преди да предадете решение се уверете, че тестовете ви се изпълняват без грешки. Това ще ви гарантира, че не сте сбъркали нещо тривиално. Например име на функция, брой приемани аргументи и подобни.
.... Finished in 0.00276 seconds 4 examples, 0 failures
.... Finished in 0.00273 seconds 4 examples, 0 failures
.... Finished in 0.00296 seconds 4 examples, 0 failures
.... Finished in 0.00279 seconds 4 examples, 0 failures
.... Finished in 0.0028 seconds 4 examples, 0 failures
.... Finished in 0.00282 seconds 4 examples, 0 failures
.... Finished in 0.00282 seconds 4 examples, 0 failures
.... Finished in 0.00277 seconds 4 examples, 0 failures
.... Finished in 0.00277 seconds 4 examples, 0 failures
.... Finished in 0.00282 seconds 4 examples, 0 failures
.... Finished in 0.00297 seconds 4 examples, 0 failures
.... Finished in 0.00276 seconds 4 examples, 0 failures
.... Finished in 0.00278 seconds 4 examples, 0 failures
.... Finished in 0.0028 seconds 4 examples, 0 failures
...F Failures: 1) #fibonacci_like? works with bigger numbers Failure/Error: expect(fibonacci_like?(sequence)).to be true expected #<TrueClass:20> => true got #<FalseClass:0> => false Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-cnoezg/spec.rb:27: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.00291 seconds 4 examples, 1 failure Failed examples: rspec /tmp/d20161030-13689-cnoezg/spec.rb:19 # #fibonacci_like? works with bigger numbers
.... Finished in 0.00284 seconds 4 examples, 0 failures
.... Finished in 0.00279 seconds 4 examples, 0 failures
.... Finished in 0.01754 seconds 4 examples, 0 failures
.... Finished in 0.0028 seconds 4 examples, 0 failures
.... Finished in 0.02063 seconds 4 examples, 0 failures
.... Finished in 0.00282 seconds 4 examples, 0 failures
.... Finished in 0.00316 seconds 4 examples, 0 failures
.... Finished in 0.00317 seconds 4 examples, 0 failures
.... Finished in 0.00303 seconds 4 examples, 0 failures
.... Finished in 0.00272 seconds 4 examples, 0 failures
FF.. Failures: 1) #fibonacci_like? works with fibonacci sequence Failure/Error: expect(fibonacci_like?([0, 1, 1, 2, 3, 6, 8, 14])).to be false expected #<FalseClass:0> => false got #<TrueClass:20> => true Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-a57jwo/spec.rb:4: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) #fibonacci_like? handles different starting numbers Failure/Error: expect(fibonacci_like?([1, 4, 6, 10, 16, 26, 42, 68])).to be false expected #<FalseClass:0> => false got #<TrueClass:20> => true Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-a57jwo/spec.rb:9: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.00285 seconds 4 examples, 2 failures Failed examples: rspec /tmp/d20161030-13689-a57jwo/spec.rb:2 # #fibonacci_like? works with fibonacci sequence rspec /tmp/d20161030-13689-a57jwo/spec.rb:7 # #fibonacci_like? handles different starting numbers
.F.. Failures: 1) #fibonacci_like? handles different starting numbers Failure/Error: expect(fibonacci_like?([1, 4, 6, 10, 16, 26, 42, 68])).to be false expected #<FalseClass:0> => false got #<TrueClass:20> => true Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-bgw0or/spec.rb:9: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 4 examples, 1 failure Failed examples: rspec /tmp/d20161030-13689-bgw0or/spec.rb:7 # #fibonacci_like? handles different starting numbers
FFFF Failures: 1) #fibonacci_like? works with fibonacci sequence Failure/Error: expect(fibonacci_like?([0, 1, 1, 2, 3, 6, 8, 14])).to be false expected #<FalseClass:0> => false got #<TrueClass:20> => true Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-12vafqi/spec.rb:4: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) #fibonacci_like? handles different starting numbers Failure/Error: expect(fibonacci_like?([1, 4, 6, 10, 16, 26, 42, 68])).to be false expected #<FalseClass:0> => false got #<TrueClass:20> => true Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-12vafqi/spec.rb:9: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) #fibonacci_like? handles sequences with negative numbers Failure/Error: expect(fibonacci_like?([-1, -2, -3, -5, -9])).to be false expected #<FalseClass:0> => false got #<TrueClass:20> => true Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-12vafqi/spec.rb:16: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)>' 4) #fibonacci_like? works with bigger numbers Failure/Error: expect(fibonacci_like?(sequence + [123])).to be false expected #<FalseClass:0> => false got #<TrueClass:20> => true Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-12vafqi/spec.rb:28: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.00964 seconds 4 examples, 4 failures Failed examples: rspec /tmp/d20161030-13689-12vafqi/spec.rb:2 # #fibonacci_like? works with fibonacci sequence rspec /tmp/d20161030-13689-12vafqi/spec.rb:7 # #fibonacci_like? handles different starting numbers rspec /tmp/d20161030-13689-12vafqi/spec.rb:14 # #fibonacci_like? handles sequences with negative numbers rspec /tmp/d20161030-13689-12vafqi/spec.rb:19 # #fibonacci_like? works with bigger numbers
.... Finished in 0.0028 seconds 4 examples, 0 failures
.... Finished in 0.00287 seconds 4 examples, 0 failures
...F Failures: 1) #fibonacci_like? works with bigger numbers Failure/Error: expect(fibonacci_like?(sequence)).to be true expected #<TrueClass:20> => true got #<FalseClass:0> => false Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-l5oaap/spec.rb:27: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.00291 seconds 4 examples, 1 failure Failed examples: rspec /tmp/d20161030-13689-l5oaap/spec.rb:19 # #fibonacci_like? works with bigger numbers
.... Finished in 0.00279 seconds 4 examples, 0 failures
.... Finished in 0.00279 seconds 4 examples, 0 failures
.... Finished in 0.00289 seconds 4 examples, 0 failures
.... Finished in 0.00282 seconds 4 examples, 0 failures
.... Finished in 0.00281 seconds 4 examples, 0 failures
.... Finished in 0.00325 seconds 4 examples, 0 failures
.... Finished in 0.00343 seconds 4 examples, 0 failures
.... Finished in 0.00278 seconds 4 examples, 0 failures
.... Finished in 0.00299 seconds 4 examples, 0 failures
...F Failures: 1) #fibonacci_like? works with bigger numbers Failure/Error: expect(fibonacci_like?(sequence)).to be true expected #<TrueClass:20> => true got #<FalseClass:0> => false Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-ir1pd9/spec.rb:27: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.01707 seconds 4 examples, 1 failure Failed examples: rspec /tmp/d20161030-13689-ir1pd9/spec.rb:19 # #fibonacci_like? works with bigger numbers
...F Failures: 1) #fibonacci_like? works with bigger numbers Failure/Error: expect(fibonacci_like?(sequence)).to be true expected #<TrueClass:20> => true got #<FalseClass:0> => false Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # /tmp/d20161030-13689-1xifuon/spec.rb:27: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.0029 seconds 4 examples, 1 failure Failed examples: rspec /tmp/d20161030-13689-1xifuon/spec.rb:19 # #fibonacci_like? works with bigger numbers
.... Finished in 0.00313 seconds 4 examples, 0 failures
.... Finished in 0.00273 seconds 4 examples, 0 failures
.... Finished in 0.00752 seconds 4 examples, 0 failures
.... Finished in 0.00333 seconds 4 examples, 0 failures
.... Finished in 0.00278 seconds 4 examples, 0 failures
.... Finished in 0.00281 seconds 4 examples, 0 failures
.... Finished in 0.00282 seconds 4 examples, 0 failures
.... Finished in 0.00277 seconds 4 examples, 0 failures
.... Finished in 0.00274 seconds 4 examples, 0 failures
.... Finished in 0.00281 seconds 4 examples, 0 failures
.... Finished in 0.00288 seconds 4 examples, 0 failures
.... Finished in 0.0027 seconds 4 examples, 0 failures
.... Finished in 0.00286 seconds 4 examples, 0 failures
.... Finished in 0.00281 seconds 4 examples, 0 failures
.... Finished in 0.00276 seconds 4 examples, 0 failures
.... Finished in 0.00285 seconds 4 examples, 0 failures
.... Finished in 0.00281 seconds 4 examples, 0 failures
.... Finished in 0.00278 seconds 4 examples, 0 failures
.... Finished in 0.00279 seconds 4 examples, 0 failures
.... Finished in 0.00272 seconds 4 examples, 0 failures
.... Finished in 0.00272 seconds 4 examples, 0 failures