Разбиване

Краен срок
26.10.2013 12:00

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

Дефинирайте функция partition(number), която приема като параметър цяло число number и връща като резултат двумерен масив от двойки естествени числа (0 е естествено), чиято сума е равна на number.

Пример за partition(5):

partition 5
> [[5, 0],
   [4, 1],
   [3, 2]]

Подредбата на двойките събираеми или на събираемите във всяка двойка не е от значение. Всяка двойка събираеми трябва да присъства точно веднъж в масива. За повторение смятаме и присъствие на двойка с разменените събираеми (ако присъства [4, 1], то трябва да не присъства и [1, 4]).

Решения

Емануела Моллова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Емануела Моллова
def partition(number)
0.upto(number/2).zip number.downto(number/2)
end
...

Finished in 0.07507 seconds
3 examples, 0 failures
Георги Пурнаров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Пурнаров
def partition (number)
list=[]
0.upto(number/2) { |num| list<<[number-num,num] }
list
end
...

Finished in 0.09187 seconds
3 examples, 0 failures
Цветан Иванов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Иванов
def partition(number)
partitions = []
first_elements = [];
(0..number).each do |current_item|
break if first_elements.include? number - current_item
partitions << [current_item, number - current_item]
first_elements << current_item
end
partitions
end
...

Finished in 0.10472 seconds
3 examples, 0 failures
Моника Ефтимова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Моника Ефтимова
def partition(number)
0.upto(number/2).zip number.downto(number/2)
end
...

Finished in 0.01274 seconds
3 examples, 0 failures
Георги Кръстев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Кръстев
def partition(number)
half = number / 2
(0.upto half).zip(number.downto half)
end
...

Finished in 0.01286 seconds
3 examples, 0 failures
Николай Каращранов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Каращранов
def partition(number)
result = []
(0..number/2).each{ |x| result << [x, number-x] }
result
end
...

Finished in 0.06445 seconds
3 examples, 0 failures
Иван Проданов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Проданов
def partition (number)
(0..number/2).each_with_object([]) { |i, pairs| pairs << [number - i, i] }
end
...

Finished in 0.09263 seconds
3 examples, 0 failures
Диан Николов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Диан Николов
def partition(number)
sums = []
(0..number/2).each { |x| sums << [x, number - x] }
sums
end
...

Finished in 0.08358 seconds
3 examples, 0 failures
Георги Ангелов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Ангелов
def partition(number)
0.upto(number / 2).map { |summand| [summand, number - summand] }
end
...

Finished in 0.00964 seconds
3 examples, 0 failures
Ясен Трифонов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Ясен Трифонов
#!/usr/local/bin/ruby -w
def partition(number)
Array.new(number / 2 + 1) { |i| [number - i, i] }
end
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
Стефан Василев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Василев
def partition(number)
result_array = []
number.downto((number / 2.0).round) { |i| result_array << [i, number - i] }
result_array
end
...

Finished in 0.07037 seconds
3 examples, 0 failures
Илия Ватахов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Илия Ватахов
def partition(number)
(0..number / 2).reduce([]) { |pairs, x| pairs << [x, number - x] }
end
...

Finished in 0.08147 seconds
3 examples, 0 failures
Деян Хаджиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Хаджиев
def partition(number)
(0..number/2).to_a.zip (number/2..number).to_a.reverse
end
...

Finished in 0.08648 seconds
3 examples, 0 failures
Росен Рачев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Росен Рачев
def partition(number)
0.upto(number / 2).zip(0.upto(number).to_a.reverse)
end
...

Finished in 0.08712 seconds
3 examples, 0 failures
Николай Хубанов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Хубанов
def partition(number)
[].tap do |result|
0.upto(number / 2) { |n| result << [n, number - n] }
end
end
...

Finished in 0.12367 seconds
3 examples, 0 failures
Христо Хърсев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Хърсев
def partition(number)
0.upto(number / 2).reduce([]) { |arr, n| arr << [n, number - n] }
end
...

Finished in 0.05897 seconds
3 examples, 0 failures
Кристиан Ташков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиан Ташков
def partition(number)
number.downto((number + 1) / 2).map { |num| [num, (number - num)]}
end
...

Finished in 0.09035 seconds
3 examples, 0 failures
Георги Гърдев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Гърдев
def partition(number)
0.upto(number / 2).map { |i| [number - i, i] }
end
...

Finished in 0.09379 seconds
3 examples, 0 failures
Александър Антов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Антов
def pair_exists?(array_of_pairs, pair)
permutations_of_pair = pair.permutation.to_a
array_of_pairs.each do |pair|
if pair == permutations_of_pair[0] or pair == permutations_of_pair[1]
return true
end
end
return false
end
def partition(element)
upper_bound = (element.to_f / 2.to_f).ceil
partitioned_array = Array.new
partition_pair = Array.new
(0..element).each do |iter|
partition_pair.push(iter)
partition_pair.push(element - iter)
if !pair_exists?(partitioned_array, partition_pair)
partitioned_array.push(partition_pair)
end
partition_pair = Array.new
end
return partitioned_array
end
...

Finished in 0.00761 seconds
3 examples, 0 failures
Мария Терзиева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Терзиева
def partition(number)
half = number / 2.0
number.downto(half.ceil).to_a.zip 0.upto(half.floor).to_a
end
...

Finished in 0.0698 seconds
3 examples, 0 failures
Мария Митева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Митева
def partition (n)
range_n = (0..n).to_a
n < 0 ? [] : range_n.zip(range_n.reverse).take((n+2)/2)
end
...

Finished in 0.10845 seconds
3 examples, 0 failures
Красимира Божанова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Красимира Божанова
def partition(number)
0.upto(number / 2).map { |element| [element, number - element] }
end
...

Finished in 0.08278 seconds
3 examples, 0 failures
Иван Латунов
  • Некоректно
  • 0 успешни тест(а)
  • 3 неуспешни тест(а)
Иван Латунов
def partiotion(n)
(0..n).to_a.zip((0..n).to_a.reverse)[0..n / 2]
end
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
Николай Генов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Генов
def partition(number)
0.upto(number / 2).map { |part| [number - part, part] }
end
...

Finished in 0.00681 seconds
3 examples, 0 failures
Георги Урумов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Урумов
def partition(number)
0.upto(number/2).map { |x| [x, number-x] }
end
...

Finished in 0.05791 seconds
3 examples, 0 failures
Сашо Михайлов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Сашо Михайлов
def partition(number)
number_help,result,counter = number,[],0
while counter <= number/2
result << [number_help,counter]
number_help-=1
counter+=1
end
return result
end
...

Finished in 0.06125 seconds
3 examples, 0 failures
Илиян Танев
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Илиян Танев
def partition(number)
pairs = []
counter = 0
number = number.abs
even = number % 2 == 0 && number != 0
begin
pairs << [number, counter]
number -= 1
counter += 1
end while(counter < number)
pairs << [number, number] if even
pairs
end
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
Михаил Господинов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Михаил Господинов
def partition(number)
(0..number/2).map do |partitioner|
[partitioner,number - partitioner]
end
end
...

Finished in 0.05536 seconds
3 examples, 0 failures
Никола Ненков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Ненков
def partition(number)
(0..number / 2).zip((number / 2..number).to_a.reverse)
end
...

Finished in 0.06348 seconds
3 examples, 0 failures
Моника Димитрова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Моника Димитрова
def partition(number)
0.upto(number / 2).collect { |addend| [number - addend, addend] }
end
...

Finished in 0.00702 seconds
3 examples, 0 failures
Методи Димитров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Методи Димитров
def partition(number)
0.upto(number / 2).map { |addend| [addend, number - addend] }
end
...

Finished in 0.07185 seconds
3 examples, 0 failures
Радослав Даскалов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Радослав Даскалов
def partition(number)
0.upto(number/2).collect{|i| [number - i, i]}
end
...

Finished in 0.13932 seconds
3 examples, 0 failures
Марио Даскалов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Марио Даскалов
def partition(number)
(0..number/2).map { |i| [i, number-i] }
end
...

Finished in 0.05213 seconds
3 examples, 0 failures
Моника Илиева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Моника Илиева
def partition(number)
(0..number).to_a.repeated_combination(2).reject { |row| row.reduce(:+) != number }
end
...

Finished in 0.00641 seconds
3 examples, 0 failures
Аделина Рудова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Аделина Рудова
def partition(number)
(0..(number / 2)).to_a.zip ((number / 2)..number).to_a.reverse
end
...

Finished in 0.10404 seconds
3 examples, 0 failures
Александър Попов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Попов
def partition(number)
return [] if number < 0
return [[0, 0]] if number.zero?
(0...number).group_by { |subtrahend| number - subtrahend }.to_a.each(&:flatten!)[0..number/2]
end
...

Finished in 0.0684 seconds
3 examples, 0 failures
Ангел Венчев
  • Некоректно
  • 1 успешни тест(а)
  • 2 неуспешни тест(а)
Ангел Венчев
def partition(num)
(0..num/2).each_with_object([]) do |i, result|
result<<[num-i,i] if num-i != i
end
end
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
Пепа Симеонова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Пепа Симеонова
def partition number
(0..number/2).collect{ |x| [number-x,x]}
end
...

Finished in 0.0672 seconds
3 examples, 0 failures
Станимир Килявков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Станимир Килявков
def partition(number)
(0..number/2).to_a.zip((number/2..number).to_a.reverse)
end
...

Finished in 0.15739 seconds
3 examples, 0 failures
Сияна Славова
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Сияна Славова
def partition(number)
if number == 0
numbers = [[0,0]];
elsif
numbers = (0..number).to_a.combination(2).to_a
numbers.keep_if { |current_sum| current_sum.reduce(:+) == number }
end
end
.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
Венцислав Велков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Венцислав Велков
def partition(number)
(0..(number / 2)).zip ((number / 2)..number).to_a.reverse
end
...

Finished in 0.11657 seconds
3 examples, 0 failures
Ангел Цанев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Цанев
def partition(number)
#first = (0..(number.quo(2).floor)).to_a
first = (0..number/2).to_a
#second = (number.downto(number.quo(2).ceil)).to_a
second = (number.downto(0)).to_a
first.zip(second)
end
...

Finished in 0.08793 seconds
3 examples, 0 failures
Илиян Бобев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Илиян Бобев
def partition(number)
0.upto(number/2).collect { |n| [n, number - n] }
end
...

Finished in 0.0764 seconds
3 examples, 0 failures
Георги Шопов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Шопов
def partition(number)
0.upto(number / 2).map { |item| [item, number - item] }
end
...

Finished in 0.05432 seconds
3 examples, 0 failures
Иван Капукаранов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Капукаранов
def partition(number)
number.downto(0).zip(0.upto number ).take number.abs / 2 + 1
end
...

Finished in 0.05281 seconds
3 examples, 0 failures
Димитър Керанов
  • Некоректно
  • 1 успешни тест(а)
  • 2 неуспешни тест(а)
Димитър Керанов
def partition(number)
return [[0, 0]] if number == 0
0.upto(number).select(&:even?).zip number.downto(0).select(&:odd?)
end
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
Антонио Николов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Антонио Николов
def partition(number)
result = []
(0..number / 2).each { |n| result << [number -n, n] }
result
end
...

Finished in 0.07569 seconds
3 examples, 0 failures
Борислава Аладжова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Борислава Аладжова
def partition(n)
sum_n = []
(0..n).to_a.repeated_combination(2).each do |addends|
sum_n << addends if addends.reduce(:+) == n
end
sum_n
end
...

Finished in 0.07605 seconds
3 examples, 0 failures
Слав Керемидчиев
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Слав Керемидчиев
def partition(number)
if number >= 0
range_of_numbers = 0.upto(number/2.ceil)
else
range_of_numbers = (number.to_f/2.ceil).to_i.upto(0)
end
range_of_numbers.map { |element| [number - element, element] }
end
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
Александър Тахчиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Тахчиев
def partition number
0.upto(number/2).reduce([]) do |answer, i|
answer << [number - i, i]
end
end
...

Finished in 0.00688 seconds
3 examples, 0 failures
Петър Мазълов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Мазълов
def partition(number)
(0..number / 2).map { |i| [number - i, i] }
end
...

Finished in 0.10626 seconds
3 examples, 0 failures
Петър Добрев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Добрев
def partition(number)
(0..number / 2).collect { |addend| [addend, number - addend] }
end
...

Finished in 0.0068 seconds
3 examples, 0 failures
Кристиян Кисимов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиян Кисимов
def partition(n)
result_array = []
(0..n).each { |item| result_array << [item, n - item] }
result_array.each { |array| array.sort! }.uniq { |i| i.first }
end
...

Finished in 0.00791 seconds
3 examples, 0 failures
Калоян Калудов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Калоян Калудов
def partition(number)
(0..number / 2).map { |i| [i , number - i] }
end
...

Finished in 0.00678 seconds
3 examples, 0 failures
Любомир Георгиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Георгиев
def partition n
(0...n/2+1).reduce([]) {|partitions, part| partitions << [part, n-part]}
end
...

Finished in 0.00617 seconds
3 examples, 0 failures
Лилия Любенова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Лилия Любенова
def partition(number)
pairs = {}
number.downto((number / 2.to_f).ceil) {|value| pairs[value] = number - value}
pairs.to_a
end
...

Finished in 0.00609 seconds
3 examples, 0 failures
Томислав Иванов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Томислав Иванов
def partition(number)
number_possible_addend = []
(0..number).each do |addend|
break if addend > number / 2
number_possible_addend << [addend, number - addend]
end
number_possible_addend
end
...

Finished in 0.00629 seconds
3 examples, 0 failures
Илия Тобов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Илия Тобов
def partition(number)
0.upto(number/2).zip number.downto number/2
end
...

Finished in 0.00741 seconds
3 examples, 0 failures
Давид Петров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Давид Петров
def partition(number)
array = []
(0..number/2).each { |x| array.push([number-x,x]) }
array
end
...

Finished in 0.00701 seconds
3 examples, 0 failures
Владимир Конушлиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Владимир Конушлиев
def partition(number)
(0..(number / 2)).map do |i|
[i, number - i]
end
end
...

Finished in 0.00768 seconds
3 examples, 0 failures
Веселин Генадиев
  • Некоректно
  • 1 успешни тест(а)
  • 2 неуспешни тест(а)
Веселин Генадиев
def partition(number)
sum_pairs = []
(number/2.floor + 1..number).each do |i|
sum_pairs.push([number - i, i])
end
sum_pairs
end
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
Милен Мавров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Милен Мавров
def partition number
partition_array = []
0.upto(number/2) { |n| partition_array << [n, number-n] }
partition_array
end
...

Finished in 0.00607 seconds
3 examples, 0 failures
Радина Петкова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Радина Петкова
def partition number
(0..number).map { |x| [x, number - x].sort }.uniq
end
...

Finished in 0.00636 seconds
3 examples, 0 failures
Кристиан Цветков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиан Цветков
def partition(number)
addends = []
middle = number/2
0.upto(middle) {|n| addends << [n, number - n]}
addends
end
...

Finished in 0.00612 seconds
3 examples, 0 failures
Цветан Коев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Коев
def partition (number)
partitions = []
(0..number/2).each { |x| partitions.push ([x, number-x]) }
partitions
end
...

Finished in 0.00613 seconds
3 examples, 0 failures
Борислава Йорданова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Борислава Йорданова
def partition(number)
pairs_of_sums = []
(0..number).each { |x| pairs_of_sums << [x,number-x] }
pairs_of_sums.delete_if do
|element| pairs_of_sums.include? element.reverse and element[0] != element[1]
end
end
...

Finished in 0.00632 seconds
3 examples, 0 failures
Добромир Младенов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Добромир Младенов
def partition(number)
division = []
if number >= 0
rightAddend = 0
leftAddend = number
until rightAddend > leftAddend
division << [rightAddend, leftAddend]
rightAddend = rightAddend + 1
leftAddend = leftAddend - 1
end
end
division
end
...

Finished in 0.00605 seconds
3 examples, 0 failures
Цани Проданов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Цани Проданов
def partition(n)
result = []
0.upto(n).to_a.reverse.each_with_index { |item, index| result << [item, index] }
n < 0 ? [] : result.take((n+2)/2)
end
...

Finished in 0.00609 seconds
3 examples, 0 failures
Петя Делчева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Петя Делчева
def partition (number)
(0..number / 2).to_a.zip((number / 2..number).to_a.reverse)
end
...

Finished in 0.00616 seconds
3 examples, 0 failures
Августина Тенчева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Августина Тенчева
def partition(number)
return_array = []
(((number + 0.0) / 2).ceil.to_int .. number).to_a.each do |i|
return_array.push [number - i, i]
end
return return_array
end
...

Finished in 0.00623 seconds
3 examples, 0 failures
Наталия Пацовска
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Наталия Пацовска
def partition(number)
(0..number / 2).map { |x| [number - x, x] }
end
...

Finished in 0.00611 seconds
3 examples, 0 failures
Иван Георгиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Георгиев
def partition number
(0..number/2).each_with_object([]) { |i, array| array << [number-i, i] }
end
...

Finished in 0.00608 seconds
3 examples, 0 failures
Никола Величков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Величков
def partition number
(0..number/2).map { |i| [number-i] << i }
end
...

Finished in 0.00608 seconds
3 examples, 0 failures