#!/usr/bin/env rhino function car(a) { return a[0]; } function cdr(a) { var na = []; var i=1; for(; i<a.length; i++) na.push(a[i]); return na; } function coin_change(amount) { var coins = [1, 5, 10, 25, 50]; function cc(a, cs) { return (a == 0) ? 1 : (a < 0 || cs.length < 1) ? 0 : cc(a - car(cs), cs) + cc(a, cdr(cs)); } return cc(amount, coins); } var n = coin_change(100); print(n);
日本語訳は評判ほど悪くない感じ。でも難しい…
undefinedが返るバグに少しハマった。
return
(a == 0) ? 1 :
(a < 0 || cs.length < 1) ? 0 :
cc(a - car(cs), cs) + cc(a, cdr(cs));