【发布时间】:2018-03-21 04:05:16
【问题描述】:
这是数字分区的代码,在最后一节中我遇到了麻烦,因为由于方法错误,我无法得到分区的数字。
class Num_Part
def Particiones n //method for the number partititons
if n == 1
return [[1]]
elsif n < 1
return [[]]
end
Particiones(n)
listaparticiones = []
for k in (n)..downto(0)
cola= Particiones(n) - k
for x in cola
particion= [k] + x
end
listaparticiones << particion
end
return listaparticiones
end
end
puts "Ingrese el Valor de N: \n" // this is where i ask for the value or the
n =Integer(gets.chomp) //number to be parted
lista = Particiones(n)
print "\n cantidad de particiones: " +String(lista.size)
lista.each do |i|
print [i]
end
obj = Num_Part.new
obj.Particiones(n)
【问题讨论】: