diff options
| author | Abigail <abigail@abigail.be> | 2021-03-22 16:18:54 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-03-22 16:18:54 +0100 |
| commit | e937ac74e25f1f977370144cbb8b82c874f83be6 (patch) | |
| tree | 081db1af7509c64c2e656357e03801b591ee744f | |
| parent | 4b69b03001a46813096697188cc3369669a3b155 (diff) | |
| download | perlweeklychallenge-club-e937ac74e25f1f977370144cbb8b82c874f83be6.tar.gz perlweeklychallenge-club-e937ac74e25f1f977370144cbb8b82c874f83be6.tar.bz2 perlweeklychallenge-club-e937ac74e25f1f977370144cbb8b82c874f83be6.zip | |
AWK, C, and Perl solution for week 105, part 1
| -rw-r--r-- | challenge-105/abigail/README.md | 3 | ||||
| -rw-r--r-- | challenge-105/abigail/awk/ch-1.awk | 22 | ||||
| -rw-r--r-- | challenge-105/abigail/c/ch-1.c | 22 | ||||
| -rw-r--r-- | challenge-105/abigail/perl/ch-1.pl | 31 | ||||
| -rw-r--r-- | challenge-105/abigail/t/ctest.ini | 11 | ||||
| -rw-r--r-- | challenge-105/abigail/t/input-1-1 | 2 | ||||
| -rw-r--r-- | challenge-105/abigail/t/output-1-1.exp | 2 |
7 files changed, 93 insertions, 0 deletions
diff --git a/challenge-105/abigail/README.md b/challenge-105/abigail/README.md index 4490f41792..8b635d6f20 100644 --- a/challenge-105/abigail/README.md +++ b/challenge-105/abigail/README.md @@ -17,6 +17,9 @@ Output: 2.02 ~~~~ ### Solutions +* [AWK](awk/ch-1.awk) +* [C](c/ch-1.c) +* [Perl](perl/ch-1.pl) ### Blog diff --git a/challenge-105/abigail/awk/ch-1.awk b/challenge-105/abigail/awk/ch-1.awk new file mode 100644 index 0000000000..9c89b72e5f --- /dev/null +++ b/challenge-105/abigail/awk/ch-1.awk @@ -0,0 +1,22 @@ +#!/usr/bin/awk + +# +# See ../README.md +# + +# +# Run as: awk -f ch-1.awk < input-file +# +# Input will consist of lines; each line will have two numbers, N and k, N > 0, +# k > 0. For each line of input, we output a line with the Nth root of k. +# +# We're not doing any input validations; we're assuming it's correct. +# + +# +# To find the Nth root of a number k, we just raise k to the power 1/N +# + +{ + printf "%.10f\n", $2 ^ (1 / $1) +} diff --git a/challenge-105/abigail/c/ch-1.c b/challenge-105/abigail/c/ch-1.c new file mode 100644 index 0000000000..0109e4c66a --- /dev/null +++ b/challenge-105/abigail/c/ch-1.c @@ -0,0 +1,22 @@ +# include <stdlib.h> +# include <stdio.h> +# include <math.h> + +/* + * See ../README.md + */ + +/* + * Run as: cc -o ch-1.o ch-1.c; ./ch-1.o < input-file + */ + +int main (void) { + long double N; + long double k; + + while (scanf ("%Lf %Lf\n", &N, &k) == 2) { + printf ("%.10Lf\n", powl (k, 1 / N)); + } + + return (0); +} diff --git a/challenge-105/abigail/perl/ch-1.pl b/challenge-105/abigail/perl/ch-1.pl new file mode 100644 index 0000000000..8360d2f37a --- /dev/null +++ b/challenge-105/abigail/perl/ch-1.pl @@ -0,0 +1,31 @@ +#!/opt/perl/bin/perl + +use 5.032; + +use strict; +use warnings; +no warnings 'syntax'; + +use experimental 'signatures'; +use experimental 'lexical_subs'; + +# +# See ../README.md +# + +# +# Run as: perl ch-1.pl < input-file +# +# Input will consist of lines; each line will have two numbers, N and k, N > 0, +# k > 0. For each line of input, we output a line with the Nth root of k. +# +# We're not doing any input validations; we're assuming it's correct. +# + +# +# To find the Nth root of a number k, we just raise k to the power 1/N +# + +$_ = [split], say $$_ [1] ** (1 / $$_ [0]) while <>; + +__END__ diff --git a/challenge-105/abigail/t/ctest.ini b/challenge-105/abigail/t/ctest.ini new file mode 100644 index 0000000000..a2212a48af --- /dev/null +++ b/challenge-105/abigail/t/ctest.ini @@ -0,0 +1,11 @@ +#
+# Configuration file for running tests, using ctest.
+# See https://github.com/Abigail/Misc/blob/master/ctest
+#
+
+[names]
+1-1 = Given examples
+
+
+[challenges/1]
+precision = 6
diff --git a/challenge-105/abigail/t/input-1-1 b/challenge-105/abigail/t/input-1-1 new file mode 100644 index 0000000000..94d627ae95 --- /dev/null +++ b/challenge-105/abigail/t/input-1-1 @@ -0,0 +1,2 @@ +5 248832 +5 34 diff --git a/challenge-105/abigail/t/output-1-1.exp b/challenge-105/abigail/t/output-1-1.exp new file mode 100644 index 0000000000..f5169ffce4 --- /dev/null +++ b/challenge-105/abigail/t/output-1-1.exp @@ -0,0 +1,2 @@ +12 +2.024397 |
