Golf をしない Code Golf
今回は Golf しなければ簡単なんだけど、繰り返しが多いものの Golf をせよというような内容なんですかね。
#! /usr/bin/gawk -f # choose.awk - get combination of n, k # http://codegolf.com/choose BEGIN { n = 100; k = 3; print combination(n, k); } # combination - return combination of n, k # input: n, k # output: combination of n, k function combination(n, k) { return fact(n) / (fact(k) * fact(n - k)); } # fact - return fact number of n # input: number # output: fact number of n function fact(n, i, f) { f = 1; if (n == 0) { return 1; } else { for (i = 1; i <= n; i++) { f = f * i; } return f; } }