Фибоначи лайк

Краен срок
29.10.2016 19:00

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

Фибоначи лайк

Дефинирайте функция fibonacci_like?, която приема списък от числа и проверява дали подадената редица "прилича" на фибоначи, т.е. всеки неин член е получен от сумата на предишните два. Нека върнатият резултат е true или false в зависимост от това дали условието е изпълнено или не. Ще подаваме редици с поне 3 числа.

Пример

fibonacci_like?([2, 6, 8, 14, 22, 36]) # => true
fibonacci_like?([0, 1, 1, 2, 3, 8])    # => false

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

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

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

Решения

Виктор Маринов
  • Коректно
  • 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
Христо Кирилов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Кирилов
def fibonacci_like?(array)
array.each_cons(3) { |a, b, c| return false if a + b != c }
true
end
....

Finished in 0.00273 seconds
4 examples, 0 failures
Никола Жишев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Жишев
def fibonacci_like?(arr)
a, b = arr
fibonacci(a, b).take(arr.size) == arr
end
def fibonacci(a, b)
# lo and behold ruby magic
Enumerator.new do |y|
loop do
y << a
a, b = b, a + b
end
end
end
....

Finished in 0.00296 seconds
4 examples, 0 failures
Лазар Дилов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Лазар Дилов
def fibonacci_like?(nums)
return true if nums[0].nil? || nums[1].nil? || nums[2].nil?
x = nums[0]
nums.shift
x + nums[0] == nums[1] && fibonacci_like?(nums)
end
....

Finished in 0.00279 seconds
4 examples, 0 failures
Делян Лафчиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Делян Лафчиев
def fibonacci_like?(seq)
if (seq.length < 3) then true
else
seq[-1] == seq[-2] + seq[-3] && fibonacci_like?(seq[0..seq.length - 2])
end
end
....

Finished in 0.0028 seconds
4 examples, 0 failures
Мая Терзиева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мая Терзиева
def fibonacci_like?(sequence)
sequence.each_cons(3).all? { |x, y, z| x + y == z }
end
....

Finished in 0.00282 seconds
4 examples, 0 failures
Петко Митков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Петко Митков
def fibonacci_like?(numbers)
numbers.each_cons(3).map { |x, y, z| x + y == z }.all?
end
....

Finished in 0.00282 seconds
4 examples, 0 failures
Здравко Петров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Здравко Петров
def fibonacci(number, bottom_one, bottom_two)
if number == 1
bottom_one
elsif number == 2
bottom_two
else
fibonacci(number-1, bottom_one, bottom_two) + fibonacci(number-2, bottom_one, bottom_two)
end
end
def fibonacci_like?(arr)
if fibonacci(arr.length, arr[0], arr[1]) == arr.last
true
else
false
end
end
....

Finished in 0.00277 seconds
4 examples, 0 failures
Александър Ойнаков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Ойнаков
def fibonacci_like?(numbers)
numbers.each_with_index do |item , index|
unless (0..1).include? index
if numbers[index - 1] + numbers[index - 2] != numbers [index]
return false
end
end
end
if (0..1).include? numbers.size
return false
end
return true
end
....

Finished in 0.00277 seconds
4 examples, 0 failures
Иво Яков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Иво Яков
def fibonacci_like?(arr)
arr.each_cons(3) { |sub| return false if sub.first(2).inject(:+) != sub.last }
true
end
....

Finished in 0.00282 seconds
4 examples, 0 failures
Даниела Русева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Даниела Русева
def fibonacci_like?(list)
hl = Hash[list.each_with_index.map { |x, i| [x, list[i - 1] + list[i - 2]] }]
hl.keys[2..-1] == hl.values[2..-1]
end
....

Finished in 0.00297 seconds
4 examples, 0 failures
Мариян Асенов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мариян Асенов
def fibonacci_like?(sequence)
fib_sequence = sequence.take(2)
fib_sequence.push(fib_sequence[-1] + fib_sequence[-2]) while fib_sequence.size < sequence.size
fib_sequence == sequence
end
....

Finished in 0.00276 seconds
4 examples, 0 failures
Йордан Иванов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Йордан Иванов
def fibonacci_like?(array)
array.each_cons(3) do |slice|
if slice[0] + slice[1] != slice[2]
return false
end
end
true
end
....

Finished in 0.00278 seconds
4 examples, 0 failures
Натали Арабаджийска
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Натали Арабаджийска
def fibonacci_like?(numbers)
numbers.each_cons(3) do |num|
return false if num[2] != num[1] + num[0]
end
true
end
....

Finished in 0.0028 seconds
4 examples, 0 failures
Кузман Белев
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Кузман Белев
def fibonacci_like?(sequence)
sequence.each_cons(3).all? { |a, b, c| (a + b).round(10) == c }
end
...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
Георги Иванов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Иванов
def fibonacci_like? (sequence)
sequence.each_cons(3).all? {|first, second, third| third == first + second}
end
....

Finished in 0.00284 seconds
4 examples, 0 failures
Добрин Цветков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Добрин Цветков
def fibonacci_like?(array)
array.each_index do |idx|
next if idx == 0 || idx == 1
return false if array[idx] != array[idx - 1] + array[idx - 2]
end
true
end
....

Finished in 0.00279 seconds
4 examples, 0 failures
Ралица Дарджонова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Ралица Дарджонова
def fibonacci_like?(array)
flag = true
array.each_with_index do |_, index|
if index > 1
flag = false if array[index] != array[index - 1] + array[index - 2]
else next
end
end
flag
end
....

Finished in 0.01754 seconds
4 examples, 0 failures
Дарин Тодоров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Дарин Тодоров
def fib_like_creator(first_element, second_element, len = nil)
new_array = []
while new_array.length < len && len do
new_array << first_element
first_element, second_element = second_element, first_element + second_element
end
new_array
end
def fibonacci_like?(sequence)
new_sequence = fib_like_creator(sequence[0], sequence[1], sequence.length)
sequence == new_sequence ? true : false
end
....

Finished in 0.0028 seconds
4 examples, 0 failures
Светослав Годжев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Светослав Годжев
require 'bigdecimal'
def fibonacci_like?(number_list)
number_list.drop(2).each_with_index do |n, i|
unless n == BigDecimal(number_list[i].to_s) + BigDecimal(number_list[i + 1].to_s)
return false
end
end
true
end
....

Finished in 0.02063 seconds
4 examples, 0 failures
Христо Христов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Христов
def fibonacci_like?(array)
true if array.each_index{ |index| if index + 2 < array.size then return false if array[index] + array[index + 1] != array[index + 2] end}
end
....

Finished in 0.00282 seconds
4 examples, 0 failures
Милена Монова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Милена Монова
def fibonacci_like?(sequence)
sequence
.each_cons(3)
.each {|triple| return false if triple[0] + triple[1] != triple[2]}
true
end
....

Finished in 0.00316 seconds
4 examples, 0 failures
Калоян Евтимов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Калоян Евтимов
def fibonacci_like?(elems)
elems.each_cons(3).map { |x, y, z| x + y == z }.all?
end
....

Finished in 0.00317 seconds
4 examples, 0 failures
Александър Илиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Илиев
def fibonacci_like?(arr)
f_like = true
(arr.size - 2).times do |index|
f_like = arr[index] + arr[index + 1] == arr[index + 2]
f_like ? next : break
end
f_like
end
....

Finished in 0.00303 seconds
4 examples, 0 failures
Исмаил Алиджиков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Исмаил Алиджиков
def fibonacci_like?(sequence)
(2..sequence.length - 1).each do |i|
return false if sequence[i - 2] + sequence[i - 1] != sequence[i]
end
return true
end
....

Finished in 0.00272 seconds
4 examples, 0 failures
Симеон Гергинов
  • Некоректно
  • 2 успешни тест(а)
  • 2 неуспешни тест(а)
Симеон Гергинов
def fibonacci_like?(numbers)
result = true
index = 0
while index + 2 < numbers.size
current = numbers[index] + numbers[index + 1]
result = current != numbers[index + 2] ? false : true
result == false unless result
index += 1
end
result
end
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
Костадин Самарджиев
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Костадин Самарджиев
def produce_fibnacci(sequence, counter)
next_number = -> (seq) { seq[seq.size - 2] + seq[seq.size - 1] }
fibonacci_seq = sequence
if fibonacci_seq.size == counter
fibonacci_seq
else
fibonacci_seq.push(next_number.call(sequence))
produce_fibnacci(fibonacci_seq, counter)
end
end
def fibonacci_like?(sequence)
fibonacci = produce_fibnacci(sequence[0..2], sequence.size)
fibonacci == sequence ? true : false
end
.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
Малина Демирова
  • Некоректно
  • 0 успешни тест(а)
  • 4 неуспешни тест(а)
Малина Демирова
require 'bigdecimal'
require 'bigdecimal/util'
def fibonacci_like?(sequence)
firstElement = sequence[0].round.abs
secondElement = sequence[-1].round
sequenceLength = sequence.length - 1
if isFibonacci?(firstElement) & isFibonacci?(secondElement)
newSequence = (firstElement..sequenceLength).map(&:fibonacci_sequence.to_proc)
end
if newSequence == sequence
return true
else
sequence.each_with_index do |element, index|
if element == (sequence[index - 1] + sequence[index - 2])
result = false
else
result = true
end
return result
end
end
end
def isFibonacci?(number)
if number == 0
return true
else
number = BigDecimal.new(number)
firstBigNumber = (5 * (number**2) + 4).sqrt(0)
secondBigNumber = (5 * (number**2) - 4).sqrt(0)
return (firstBigNumber == firstBigNumber.round || secondBigNumber == secondBigNumber.round)
end
end
class Fixnum
def fibonacci_sequence
phi = (1 + Math.sqrt(5)) / 2
((phi**self - (-1 / phi)**self) / Math.sqrt(5)).to_i
end
end
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
Методи Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Методи Димитров
def fibonacci_like?(array)
array.each_cons(3).map { |x, y, z| x + y == z }.all?
end
....

Finished in 0.0028 seconds
4 examples, 0 failures
София Петрова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
София Петрова
def fibonacci_like?(arr)
arr.each_with_index.map do |number, index|
if arr.length - 2 > index
(number + arr[index+1]).round(5) == arr[index+2].round(5)
end
end.compact.all?
end
....

Finished in 0.00287 seconds
4 examples, 0 failures
Петър Нетовски
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Петър Нетовски
def fibonacci_like?(sequence)
sequence.each_cons(3) { |group| return false if (group[0] + group[1]).round(2) != group[2] }
true
end
...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
Мартин Христов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мартин Христов
def fibonacci_like?(sequence)
isFibonacci = false;
for i in 0..(sequence.size-3)
if (sequence[i] + sequence[i+1] == sequence[i+2])
isFibonacci = true;
else
return false;
end
end
isFibonacci;
end
....

Finished in 0.00279 seconds
4 examples, 0 failures
Петър Велев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Велев
def fibonacci_like? (arr)
counter = 2 #elements are 2 more than the number of subarrays
arr.each_cons(3) {|nums| counter+=1 if nums[0] + nums[1] == nums[2] }
counter == arr.length
end
....

Finished in 0.00279 seconds
4 examples, 0 failures
Николина Гюрова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Николина Гюрова
def fibonacci_like?(sequence)
result = sequence.select.with_index do |n, i|
i == 0 || i == 1 ||
n == sequence[i - 2] + sequence[i - 1]
end
(sequence - result).empty?
end
....

Finished in 0.00289 seconds
4 examples, 0 failures
Христина Тодорова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Христина Тодорова
def fibonacci_like?(array)
first, second = array[0], array[1]
array[2..array.size].each_with_index do |_, index|
return false unless array[2..array.size][index] == first + second
first, second = second, first + second
end
true
end
....

Finished in 0.00282 seconds
4 examples, 0 failures
Ивайло Дончев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Ивайло Дончев
def fibonacci_like?(list_of_integers)
list_length = list_of_integers.length
list_is_fibonacci = true
if list_length < 3
list_is_fibonacci = false
end
indexes = Array((2..list_length - 1))
indexes.each do |index|
if list_of_integers[index] != list_of_integers[index - 1] + list_of_integers[index - 2]
list_is_fibonacci = false
end
end
list_is_fibonacci
end
....

Finished in 0.00281 seconds
4 examples, 0 failures
Божидар Михайлов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Божидар Михайлов
def fibonacci_like?(seq)
seq[2..-1] == seq[0..-3].zip(seq[1..-2]).map { |x, y| x + y }
end
....

Finished in 0.00325 seconds
4 examples, 0 failures
Цветан Христов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Христов
def fibonacci_like?(arr)
arr.each_cons(3) { |sub_arr| return false if sub_arr.last != sub_arr.take(2).reduce(:+) }
true
end
....

Finished in 0.00343 seconds
4 examples, 0 failures
Виктор Клисуров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Виктор Клисуров
def fibonacci_like?(list)
list[2..-1].collect.with_index { |e, i| e == list[i + 1] + list[i] }.all?
end
....

Finished in 0.00278 seconds
4 examples, 0 failures
Момчил Баталов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Момчил Баталов
def fibonacci_like?(input_array)
isTrue = true
if(input_array.size < 3)
return "Wrong input!"
end
i = 2
while (i < input_array.size)
if input_array[i] == input_array[i - 1] + input_array[i - 2]
isTrue = true
else
isTrue = false
break
end
i += 1
end
if isTrue
return true
else
return false
end
end
....

Finished in 0.00299 seconds
4 examples, 0 failures
Михаил Здравков
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Михаил Здравков
def fibonacci_like?(numbers)
numbers[2..-1].reduce numbers[0..1] do |last_two, current|
return false if last_two.map(&:to_f).reduce(&:+) != current.to_f
[last_two.last, current]
end
true
end
...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
Стамен Драгоев
  • Некоректно
  • 3 успешни тест(а)
  • 1 неуспешни тест(а)
Стамен Драгоев
def fibonacci_like?(arr)
(arr.length - 2).times do |index|
return false if (arr[index] + arr[index + 1]).round(5) != arr[index + 2]
end
true
end
...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
Константин Нецов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Нецов
def fibonacci_like?(seq)
array = []
seq.each_cons(3) { |arr| array << (arr[2] == arr[1] + arr[0]) }
array.all?
end
....

Finished in 0.00313 seconds
4 examples, 0 failures
Мила Бянкова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Мила Бянкова
def fibonacci_like?(sequence)
sequence.each_with_index.all? do |element, index|
if index >= 2
element == sequence[index - 1] + sequence[index - 2]
else
true
end
end
end
....

Finished in 0.00273 seconds
4 examples, 0 failures
Васил Чимев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Васил Чимев
def fibonacci_like?(array)
fib_like = []
array.each_cons(3) do |subarray|
if subarray[0] + subarray[1] == subarray[2]
fib_like.push true
else
fib_like.push false
end
end
fib_like.include?(false) ? false : true
end
....

Finished in 0.00752 seconds
4 examples, 0 failures
Антон Сотиров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Антон Сотиров
def fibonacci_like?(array)
first = array[0]
second = array[1]
array = array.drop(2)
array.each do |elem|
if(first + second != elem)
return false
end
first = second
second = elem
end
return true
end
....

Finished in 0.00333 seconds
4 examples, 0 failures
Константин Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Константин Димитров
def fibonacci_like?(sequence)
sequence[2..-1].each_index { |x| if sequence[x] + sequence[x + 1] != sequence[x + 2] then return false end }
true
end
....

Finished in 0.00278 seconds
4 examples, 0 failures
Кристъфър Коруев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Кристъфър Коруев
def fibonacci_like?(list)
is_fibonacci_like = lambda do |list|
flag = (list[0] + list[1]) == list[2]
return flag if list.length == 3
return is_fibonacci_like.call(list[1, list.length]) if flag
flag
end
is_fibonacci_like.call(list)
end
....

Finished in 0.00281 seconds
4 examples, 0 failures
Сияна Плачкова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Сияна Плачкова
def fibonacci_like?(numbers_list)
check_list = numbers_list.each_cons(3)
check_list.all? { |triple| triple[0] + triple[1] == triple[2] }
end
....

Finished in 0.00282 seconds
4 examples, 0 failures
Милен Дончев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Милен Дончев
def fibonacci_like? numbers
count = 0
numbers[2..-1].each_with_index { |value, i| (numbers[i] + numbers[i + 1] == numbers[i + 2]) ? count += 1 : 0 }
count == numbers.length - 2
end
....

Finished in 0.00277 seconds
4 examples, 0 failures
Теодора Петкова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Теодора Петкова
def fibonacci_like?(array)
array.drop(2).reduce(array.take(2)) { |a, b| a[-2] + a[-1] == b ? a << b : a }.size == array.size
end
....

Finished in 0.00274 seconds
4 examples, 0 failures
Георги Карапетров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Карапетров
def fibonacci_first_triplet?(sequence)
return false if sequence.length < 3
sequence[0] + sequence[1] == sequence[2]
end
def fibonacci_like?(sequence)
return true if sequence.length == 3 and fibonacci_first_triplet?(sequence)
fibonacci_first_triplet?(sequence) && fibonacci_like?(sequence.drop(1))
end
....

Finished in 0.00281 seconds
4 examples, 0 failures
Калина Бухлева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Калина Бухлева
def fibonacci_like?(data)
return false if data.size < 3
data.each_cons(3) do |cons|
return false if (cons[0] + cons[1] - cons[2]).abs > 0.00001
end
true
end
....

Finished in 0.00288 seconds
4 examples, 0 failures
Валентин Георгиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Валентин Георгиев
def fibonacci_like?(f_nums)
f_nums.each_index do |index|
next_index = index + 1
if f_nums[next_index + 1]
fib_check = f_nums[index] + f_nums[next_index] == f_nums[next_index + 1]
return false unless fib_check
end
end
true
end
....

Finished in 0.0027 seconds
4 examples, 0 failures
Станислав Димитров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Станислав Димитров
def fibonacci_like?(arr)
result = []
arr_size = arr.length-2
arr.each_with_index do |_,index|
if index < arr_size
result << ((arr[index] + arr[index+1]).round(4) == arr[index+2].round(4))
end
end
result.include?(false) ? false : true
end
....

Finished in 0.00286 seconds
4 examples, 0 failures
Елеонора Кайкова
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Елеонора Кайкова
def fibonacci_like?( numbers )
numbers.each_cons(3).all? { |x, y, z| x + y == z }
end
....

Finished in 0.00281 seconds
4 examples, 0 failures
Иван Станков
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Станков
def fibonacci_like?(array)
result = true
array.each_index do |x|
result = array[x] + array[x + 1] == array[x + 2] unless x > array.count - 3
if result == false then return result end
end
result
end
....

Finished in 0.00276 seconds
4 examples, 0 failures
Петър Скорчелиев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Скорчелиев
def fibonacci_like?(array)
array.each_cons(3).to_a.reduce(true) do |all_trios_fibonacci_like, trio|
all_trios_fibonacci_like && trio[0] + trio[1] == trio[2]
end
end
....

Finished in 0.00285 seconds
4 examples, 0 failures
Теодор Филипов
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Теодор Филипов
def fibonacci_like? (a_list)
a_list.each_cons(3).map { |cons| cons[0] + cons[1] == cons[2] }.all?
end
....

Finished in 0.00281 seconds
4 examples, 0 failures
Радослав Гайдаров
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Радослав Гайдаров
def fibonacci_like?(array_of_numbers)
array_of_numbers.each_cons(3) do |sub_array|
return false if sub_array[0] + sub_array[1] != sub_array[-1]
end
true
end
....

Finished in 0.00278 seconds
4 examples, 0 failures
Красимир Тренчев
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Красимир Тренчев
# def fibonacci_like?(seq)
# res_index = 2
# while res_index < seq.length do
# first = Complex(seq[res_index - 2])
# second = Complex(seq[res_index - 1])
# result = Complex(seq[res_index])
# return false unless first + second == result
# res_index += 1
# end
# true
# end
def fibonacci_like?(seq)
return true unless seq.length > 2
head, *tail = seq
(head + tail[0] == tail[1]) && fibonacci_like?(tail)
end
....

Finished in 0.00279 seconds
4 examples, 0 failures
Беатрис Бонева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Беатрис Бонева
def fibonacci_like?(numbers)
first, second, third = *numbers[0..2]
is_fibonacci_like_num = (first + second == third)
next_numbers = numbers.drop(1)
if next_numbers.size < 3
is_fibonacci_like_num
else
is_fibonacci_like_num ? fibonacci_like?(next_numbers) : false
end
end
....

Finished in 0.00272 seconds
4 examples, 0 failures
Добромира Лозева
  • Коректно
  • 4 успешни тест(а)
  • 0 неуспешни тест(а)
Добромира Лозева
def fibonacci_like?(n)
n.each_with_index do |x,i|
if(i < n.size - 2)
then
k=i+1
if(n[i] + n[k] != n[k+1]) then return false end
end
end
true
end
....

Finished in 0.00272 seconds
4 examples, 0 failures