Add tags

Add tags to the following comment

分解後の数字が2桁の場合の処理を簡潔に書く方法を思いつかなかったのと、スピードアップのために方針変更。 1桁目はnから0、2桁目は(n-1桁目)から0、...としました。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
def divNat(n, m, acc = [])
  if m == 1
    p acc << n
    return
  end
  n.downto(0) {|i|
    w = acc[0..-1]
    divNat(n-i,m-1, w << i)
  }
end

divNat(5,3)

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...