Comment detail

自然数の分割 (Nested Flatten)
push とか unshift は元の配列を返してくれれば便利なのに。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
function doukaku89(n, m){
  if(--m < 1) return [[n]];
  for(var r = [], i = n, x = 0; i >= 0; i--)
    for(var a = arguments.callee(n - i, m), j = 0, l = a.length; j < l; j++)
      r[x++] = (a[j].unshift(i), a[j]);
  return r;
}

(typeof alert != 'undefined' ? alert :
 typeof print != 'undefined' ? print :
 function($){ typeof WSH == 'object' && WSH.echo($) })(doukaku89(5, 3).join('\n'))

Index

Feed

Other

Link

Pathtraq

loading...