Add tags

Add tags to the following comment
例えば(5,3)の場合、基数変換で[5,0,0]から[0,0,5]までの配列を生成後、合計が5のものだけ出力しています。
1
2
3
4
5
6
7
8
def divNat(n,m)
  ((n + 1)**(m - 1) * n).downto(0) {|i|
    w = sprintf("%0#{m}d",i.to_s(n + 1)).split(//).map {|j|j.to_i}
    p w if w.inject(0){|r,j|r += j} == n
  }
end

divNat(5,3)

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...