diff options
| author | wukong <wukong@longaeva> | 2023-12-18 12:37:31 -0800 |
|---|---|---|
| committer | wukong <wukong@longaeva> | 2023-12-18 12:37:31 -0800 |
| commit | 309c5d8f7ff8c36235222d079955cd3783bb7ad0 (patch) | |
| tree | 22fa0994657cee27292ef1531211a47293afab5f /binom_coeff.awk | |
| parent | 0c1d68ee8cc2a631d6029285e771ebbfe119995d (diff) | |
Added a partially working function performing LU decomposition on a square
matrix, ludcmp.awk. This is providing correct answers on _some_ test data,
further testing debugging required here.
Diffstat (limited to '')
| -rw-r--r-- | binom_coeff.awk | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/binom_coeff.awk b/binom_coeff.awk new file mode 100644 index 0000000..a19f464 --- /dev/null +++ b/binom_coeff.awk @@ -0,0 +1,18 @@ +#! /usr/bin/awk -f + +### binomial coeffecient +# https://rosettacode.org/wiki/Evaluate_binomial_coefficients +function binom(n, k) { + b = 1 + for (i=1; i<(k+1); i++) { + b *= (n - i + 1) / i + } + return b +} + +BEGIN { + ARGV[1] ? N = ARGV[1] : N = 1 + ARGV[2] ? K = ARGV[2] : K = 1 + ARGV[3] ? OFMT = "%." ARGV[3] "g" : OFMT = "%g" + printf(OFMT ORS, binom(N, K)) +} |
