@pimsteenbergh/

HummingKaleidoscopicDunnart

PHP (Legacy)

No description

fork
loading
main.php
1
2
3
4
5
6
7
8
9
function f($a,$n){$r=$n>0?[]:[[]];if([$k,$v]=each($a)){unset($a[$k]);$r=f($a,$n);foreach(f($a,$n-$v)as$t){$t[]=$k;$r[]=$t;}}return$r;}

$p = array( "a"=>3
, "b"=>2
, "c"=>5
, "d"=>1
  );
  
print_r(f($p,10));
PHP 7.0.8 (Legacy: use the following for new features: Command-line PHP: https://repl.it/languages/php_cli PHP Web Server: https://repl.it/languages/php7