- Коректно
- 3 успешни тест(а)
- 0 неуспешни тест(а)
def partition(number)
0.upto(number/2).zip number.downto(number/2)
end
... Finished in 0.07507 seconds 3 examples, 0 failures
Срокът за предаване на решения е отминал
Дефинирайте функция partition(number)
, която приема като параметър цяло число
number
и връща като резултат двумерен масив от двойки естествени числа (0 е
естествено), чиято сума е равна на number
.
Пример за partition(5)
:
partition 5
> [[5, 0],
[4, 1],
[3, 2]]
Подредбата на двойките събираеми или на събираемите във всяка двойка не е от
значение. Всяка двойка събираеми трябва да присъства точно веднъж в масива. За
повторение смятаме и присъствие на двойка с разменените събираеми (ако
присъства [4, 1]
, то трябва да не присъства и [1, 4]
).
... Finished in 0.07507 seconds 3 examples, 0 failures
... Finished in 0.09187 seconds 3 examples, 0 failures
... Finished in 0.10472 seconds 3 examples, 0 failures
... Finished in 0.01274 seconds 3 examples, 0 failures
... Finished in 0.01286 seconds 3 examples, 0 failures
... Finished in 0.06445 seconds 3 examples, 0 failures
... Finished in 0.09263 seconds 3 examples, 0 failures
... Finished in 0.08358 seconds 3 examples, 0 failures
... Finished in 0.00964 seconds 3 examples, 0 failures
F.. Failures: 1) partition returns an array containing partitions of the integer Failure/Error: partition(-42).should eq [] ArgumentError: negative array size # /tmp/d20131106-4393-191dq3f/solution.rb:4:in `initialize' # /tmp/d20131106-4393-191dq3f/solution.rb:4:in `new' # /tmp/d20131106-4393-191dq3f/solution.rb:4:in `partition' # /tmp/d20131106-4393-191dq3f/spec.rb:3: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.03033 seconds 3 examples, 1 failure Failed examples: rspec /tmp/d20131106-4393-191dq3f/spec.rb:2 # partition returns an array containing partitions of the integer
... Finished in 0.07037 seconds 3 examples, 0 failures
... Finished in 0.08147 seconds 3 examples, 0 failures
... Finished in 0.08648 seconds 3 examples, 0 failures
... Finished in 0.08712 seconds 3 examples, 0 failures
... Finished in 0.12367 seconds 3 examples, 0 failures
... Finished in 0.05897 seconds 3 examples, 0 failures
... Finished in 0.09035 seconds 3 examples, 0 failures
... Finished in 0.09379 seconds 3 examples, 0 failures
... Finished in 0.00761 seconds 3 examples, 0 failures
... Finished in 0.0698 seconds 3 examples, 0 failures
... Finished in 0.10845 seconds 3 examples, 0 failures
... Finished in 0.08278 seconds 3 examples, 0 failures
FFF Failures: 1) partition returns an array containing partitions of the integer Failure/Error: partition(-42).should eq [] NoMethodError: undefined method `partition' for #<RSpec::Core::ExampleGroup::Nested_1:0xba66b844> # /tmp/d20131106-4393-13f2e65/spec.rb:3: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) partition returns the correct number of partitions Failure/Error: partition(5).should have_exactly(3).items NoMethodError: undefined method `partition' for #<RSpec::Core::ExampleGroup::Nested_1:0xba66a8cc> # /tmp/d20131106-4393-13f2e65/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) partition does not return duplicate partitions Failure/Error: partitions = partition(10) NoMethodError: undefined method `partition' for #<RSpec::Core::ExampleGroup::Nested_1:0xba6699f4> # /tmp/d20131106-4393-13f2e65/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)>' Finished in 0.05986 seconds 3 examples, 3 failures Failed examples: rspec /tmp/d20131106-4393-13f2e65/spec.rb:2 # partition returns an array containing partitions of the integer rspec /tmp/d20131106-4393-13f2e65/spec.rb:9 # partition returns the correct number of partitions rspec /tmp/d20131106-4393-13f2e65/spec.rb:14 # partition does not return duplicate partitions
... Finished in 0.00681 seconds 3 examples, 0 failures
... Finished in 0.05791 seconds 3 examples, 0 failures
... Finished in 0.06125 seconds 3 examples, 0 failures
F.. Failures: 1) partition returns an array containing partitions of the integer Failure/Error: partition(-42).should eq [] expected: [] got: [[42, 0], [41, 1], [40, 2], [39, 3], [38, 4], [37, 5], [36, 6], [35, 7], [34, 8], [33, 9], [32, 10], [31, 11], [30, 12], [29, 13], [28, 14], [27, 15], [26, 16], [25, 17], [24, 18], [23, 19], [22, 20], [21, 21]] (compared using ==) # /tmp/d20131106-4393-1kjnfl5/spec.rb:3: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.07087 seconds 3 examples, 1 failure Failed examples: rspec /tmp/d20131106-4393-1kjnfl5/spec.rb:2 # partition returns an array containing partitions of the integer
... Finished in 0.05536 seconds 3 examples, 0 failures
... Finished in 0.06348 seconds 3 examples, 0 failures
... Finished in 0.00702 seconds 3 examples, 0 failures
... Finished in 0.07185 seconds 3 examples, 0 failures
... Finished in 0.13932 seconds 3 examples, 0 failures
... Finished in 0.05213 seconds 3 examples, 0 failures
... Finished in 0.00641 seconds 3 examples, 0 failures
... Finished in 0.10404 seconds 3 examples, 0 failures
... Finished in 0.0684 seconds 3 examples, 0 failures
FF. Failures: 1) partition returns an array containing partitions of the integer Failure/Error: partition(0).should eq [[0, 0]] expected: [[0, 0]] got: [] (compared using ==) # /tmp/d20131106-4393-3g38dh/spec.rb:4: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) partition returns the correct number of partitions Failure/Error: partition(10).should have_exactly(6).items expected 6 items, got 5 # /tmp/d20131106-4393-3g38dh/spec.rb:11: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.05983 seconds 3 examples, 2 failures Failed examples: rspec /tmp/d20131106-4393-3g38dh/spec.rb:2 # partition returns an array containing partitions of the integer rspec /tmp/d20131106-4393-3g38dh/spec.rb:9 # partition returns the correct number of partitions
... Finished in 0.0672 seconds 3 examples, 0 failures
... Finished in 0.15739 seconds 3 examples, 0 failures
.F. Failures: 1) partition returns the correct number of partitions Failure/Error: partition(10).should have_exactly(6).items expected 6 items, got 5 # /tmp/d20131106-4393-ios52n/spec.rb:11: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.06527 seconds 3 examples, 1 failure Failed examples: rspec /tmp/d20131106-4393-ios52n/spec.rb:9 # partition returns the correct number of partitions
... Finished in 0.11657 seconds 3 examples, 0 failures
... Finished in 0.08793 seconds 3 examples, 0 failures
... Finished in 0.0764 seconds 3 examples, 0 failures
... Finished in 0.05432 seconds 3 examples, 0 failures
... Finished in 0.05281 seconds 3 examples, 0 failures
F.F Failures: 1) partition returns an array containing partitions of the integer Failure/Error: partition(10).map { |addends| addends.reduce(:+) }.all? { |sum| sum.should eq 10 } TypeError: nil can't be coerced into Fixnum # /tmp/d20131106-4393-2c4sy/spec.rb:6:in `+' # /tmp/d20131106-4393-2c4sy/spec.rb:6:in `each' # /tmp/d20131106-4393-2c4sy/spec.rb:6:in `reduce' # /tmp/d20131106-4393-2c4sy/spec.rb:6:in `block (3 levels) in <top (required)>' # /tmp/d20131106-4393-2c4sy/spec.rb:6:in `map' # /tmp/d20131106-4393-2c4sy/spec.rb:6: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) partition does not return duplicate partitions Failure/Error: unique_partitions = partitions.uniq { |addends| addends.sort } ArgumentError: comparison of Fixnum with nil failed # /tmp/d20131106-4393-2c4sy/spec.rb:16:in `sort' # /tmp/d20131106-4393-2c4sy/spec.rb:16:in `block (3 levels) in <top (required)>' # /tmp/d20131106-4393-2c4sy/spec.rb:16:in `uniq' # /tmp/d20131106-4393-2c4sy/spec.rb:16: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.06758 seconds 3 examples, 2 failures Failed examples: rspec /tmp/d20131106-4393-2c4sy/spec.rb:2 # partition returns an array containing partitions of the integer rspec /tmp/d20131106-4393-2c4sy/spec.rb:14 # partition does not return duplicate partitions
... Finished in 0.07569 seconds 3 examples, 0 failures
... Finished in 0.07605 seconds 3 examples, 0 failures
F.. Failures: 1) partition returns an array containing partitions of the integer Failure/Error: partition(-42).should eq [] expected: [] got: [[-21, -21], [-22, -20], [-23, -19], [-24, -18], [-25, -17], [-26, -16], [-27, -15], [-28, -14], [-29, -13], [-30, -12], [-31, -11], [-32, -10], [-33, -9], [-34, -8], [-35, -7], [-36, -6], [-37, -5], [-38, -4], [-39, -3], [-40, -2], [-41, -1], [-42, 0]] (compared using ==) # /tmp/d20131106-4393-1c1o07z/spec.rb:3: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.19709 seconds 3 examples, 1 failure Failed examples: rspec /tmp/d20131106-4393-1c1o07z/spec.rb:2 # partition returns an array containing partitions of the integer
... Finished in 0.00688 seconds 3 examples, 0 failures
... Finished in 0.10626 seconds 3 examples, 0 failures
... Finished in 0.0068 seconds 3 examples, 0 failures
... Finished in 0.00791 seconds 3 examples, 0 failures
... Finished in 0.00678 seconds 3 examples, 0 failures
... Finished in 0.00617 seconds 3 examples, 0 failures
... Finished in 0.00609 seconds 3 examples, 0 failures
... Finished in 0.00629 seconds 3 examples, 0 failures
... Finished in 0.00741 seconds 3 examples, 0 failures
... Finished in 0.00701 seconds 3 examples, 0 failures
... Finished in 0.00768 seconds 3 examples, 0 failures
FF. Failures: 1) partition returns an array containing partitions of the integer Failure/Error: partition(0).should eq [[0, 0]] expected: [[0, 0]] got: [] (compared using ==) # /tmp/d20131106-4393-cxhu3b/spec.rb:4: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) partition returns the correct number of partitions Failure/Error: partition(10).should have_exactly(6).items expected 6 items, got 5 # /tmp/d20131106-4393-cxhu3b/spec.rb:11: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.00745 seconds 3 examples, 2 failures Failed examples: rspec /tmp/d20131106-4393-cxhu3b/spec.rb:2 # partition returns an array containing partitions of the integer rspec /tmp/d20131106-4393-cxhu3b/spec.rb:9 # partition returns the correct number of partitions
... Finished in 0.00607 seconds 3 examples, 0 failures
... Finished in 0.00636 seconds 3 examples, 0 failures
... Finished in 0.00612 seconds 3 examples, 0 failures
... Finished in 0.00613 seconds 3 examples, 0 failures
... Finished in 0.00632 seconds 3 examples, 0 failures
... Finished in 0.00605 seconds 3 examples, 0 failures
... Finished in 0.00609 seconds 3 examples, 0 failures
... Finished in 0.00616 seconds 3 examples, 0 failures
... Finished in 0.00623 seconds 3 examples, 0 failures
... Finished in 0.00611 seconds 3 examples, 0 failures
... Finished in 0.00608 seconds 3 examples, 0 failures
... Finished in 0.00608 seconds 3 examples, 0 failures