From 309c5d8f7ff8c36235222d079955cd3783bb7ad0 Mon Sep 17 00:00:00 2001 From: wukong Date: Mon, 18 Dec 2023 12:37:31 -0800 Subject: 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. --- binom_coeff.awk | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 binom_coeff.awk (limited to 'binom_coeff.awk') 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)) +} -- cgit v1.2.3