Решение на Първа задача от Димитър Шукерски

Обратно към всички решения

Към профила на Димитър Шукерски

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 12 неуспешни тест(а)

Код

def fibonacci(n)
return 1 if n == 1 or n == 2
return fibonacci(n-1) + fibonacci(n-2)
end
def lucas(n)
return 2 if n == 1
return 1 if n == 2
return lucas(n-1) + lucas(n-2)
end
def summed(n)
fibonacci(n) + lucas(n)
end
def series(name, n)
puts send(name, n)
end

Лог от изпълнението

1
F13
F21
F610
F2
F18
F29
F843
F3
F31
F50
F1453
F

Failures:

  1) series handles fibonacci series for base cases
     Failure/Error: series('fibonacci', 1).should eq 1
       
       expected: 1
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:5:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) series handles fibonacci series for odd numbers
     Failure/Error: series('fibonacci', 7).should eq 13
       
       expected: 13
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:10:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) series handles fibonacci series for even numbers
     Failure/Error: series('fibonacci', 8).should eq 21
       
       expected: 21
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:15:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) series handles fibonacci series for bigger numbers
     Failure/Error: series('fibonacci', 15).should eq 610
       
       expected: 610
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:20:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) series handles lucas series for base cases
     Failure/Error: series('lucas', 1).should eq 2
       
       expected: 2
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:25:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) series handles lucas series for odd numbers
     Failure/Error: series('lucas', 7).should eq 18
       
       expected: 18
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:30:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) series handles lucas series for even numbers
     Failure/Error: series('lucas', 8).should eq 29
       
       expected: 29
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:35:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) series handles lucas series for bigger numbers
     Failure/Error: series('lucas', 15).should eq 843
       
       expected: 843
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:40:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) series handles summed series for base cases
     Failure/Error: series('summed', 1).should eq 3
       
       expected: 3
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:45:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) series handles summed series for odd numbers
     Failure/Error: series('summed', 7).should eq 31
       
       expected: 31
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:50:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) series handles summed series for even numbers
     Failure/Error: series('summed', 8).should eq 50
       
       expected: 50
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:55:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) series handles summed series for bigger numbers
     Failure/Error: series('summed', 15).should eq 1453
       
       expected: 1453
            got: nil
       
       (compared using ==)
     # /tmp/d20141023-2426-ixwco5/spec.rb:60:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.01201 seconds
12 examples, 12 failures

Failed examples:

rspec /tmp/d20141023-2426-ixwco5/spec.rb:4 # series handles fibonacci series for base cases
rspec /tmp/d20141023-2426-ixwco5/spec.rb:9 # series handles fibonacci series for odd numbers
rspec /tmp/d20141023-2426-ixwco5/spec.rb:14 # series handles fibonacci series for even numbers
rspec /tmp/d20141023-2426-ixwco5/spec.rb:19 # series handles fibonacci series for bigger numbers
rspec /tmp/d20141023-2426-ixwco5/spec.rb:24 # series handles lucas series for base cases
rspec /tmp/d20141023-2426-ixwco5/spec.rb:29 # series handles lucas series for odd numbers
rspec /tmp/d20141023-2426-ixwco5/spec.rb:34 # series handles lucas series for even numbers
rspec /tmp/d20141023-2426-ixwco5/spec.rb:39 # series handles lucas series for bigger numbers
rspec /tmp/d20141023-2426-ixwco5/spec.rb:44 # series handles summed series for base cases
rspec /tmp/d20141023-2426-ixwco5/spec.rb:49 # series handles summed series for odd numbers
rspec /tmp/d20141023-2426-ixwco5/spec.rb:54 # series handles summed series for even numbers
rspec /tmp/d20141023-2426-ixwco5/spec.rb:59 # series handles summed series for bigger numbers

История (2 версии и 1 коментар)

Димитър обнови решението на 15.10.2014 00:16 (преди около 10 години)

+def fibonacci(n)
+ return 1 if n == 1 || n == 2
+ return fibonacci(n-1) + fibonacci(n-2)
+end
+
+def lucas(n)
+ return 2 if n == 1
+ return 1 if n == 2
+ return lucas(n-1) + lucas(n-2)
+end
+
+def summed(n)
+ fibonacci(n) + lucas(n)
+end
+
+def series(name, n)
+puts send(name, n)
+end
  • Прочети style guide-а, определено виж секцията за идентацията.
  • Решението ти ми харесва като цяло, но за в бъдеще си пускай примерните тестове. Очаква се функцията да връща стойност, не да го принтира.
  • Съветвам те да не предаваш в последният момент.

Димитър обнови решението на 15.10.2014 16:46 (преди около 10 години)

def fibonacci(n)
- return 1 if n == 1 || n == 2
+ return 1 if n == 1 or n == 2
return fibonacci(n-1) + fibonacci(n-2)
end
def lucas(n)
return 2 if n == 1
return 1 if n == 2
return lucas(n-1) + lucas(n-2)
end
def summed(n)
fibonacci(n) + lucas(n)
end
def series(name, n)
puts send(name, n)
end