aboutsummaryrefslogtreecommitdiff
path: root/challenge-105
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2021-03-28 22:36:05 +0100
committerGitHub <noreply@github.com>2021-03-28 22:36:05 +0100
commit86e44e2deac4c2163bbe9ec2819e5bd89668a55f (patch)
tree9604205c4d1c52437b85c5199a9fbd902abfa66d /challenge-105
parent00bc007b610d2755e1157232859380bcaf824385 (diff)
parent31d85e3399763330fb11be244f132a7c50bd3f4c (diff)
downloadperlweeklychallenge-club-86e44e2deac4c2163bbe9ec2819e5bd89668a55f.tar.gz
perlweeklychallenge-club-86e44e2deac4c2163bbe9ec2819e5bd89668a55f.tar.bz2
perlweeklychallenge-club-86e44e2deac4c2163bbe9ec2819e5bd89668a55f.zip
Merge pull request #3790 from Abigail/abigail/week-105
Abigail/week 105
Diffstat (limited to 'challenge-105')
-rw-r--r--challenge-105/abigail/README.md2
-rw-r--r--challenge-105/abigail/pascal/ch-1.p39
-rw-r--r--challenge-105/abigail/scheme/ch-1.scm31
3 files changed, 72 insertions, 0 deletions
diff --git a/challenge-105/abigail/README.md b/challenge-105/abigail/README.md
index b45353bc37..c503be0687 100644
--- a/challenge-105/abigail/README.md
+++ b/challenge-105/abigail/README.md
@@ -23,9 +23,11 @@ Output: 2.02
* [Fortran](fortran/ch-1.f90)
* [Lua](lua/ch-1.lua)
* [Node.js](node/ch-1.js)
+* [Pascal](pascal/ch-1.p)
* [Perl](perl/ch-1.pl)
* [Python](python/ch-1.py)
* [Ruby](ruby/ch-1.rb)
+* [Scheme](scheme/ch-1.scm)
* [SQL](sql/ch-1.sql)
### Blog
diff --git a/challenge-105/abigail/pascal/ch-1.p b/challenge-105/abigail/pascal/ch-1.p
new file mode 100644
index 0000000000..49eee20c4f
--- /dev/null
+++ b/challenge-105/abigail/pascal/ch-1.p
@@ -0,0 +1,39 @@
+Program NthRoot;
+
+(* *)
+(* See ../README.md *)
+(* *)
+
+(* *)
+(* Run as: fpc -och-1.out ch-1.p; ./ch-1.out *)
+(* *)
+
+(* *)
+(* 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 calculate: *)
+(* *)
+(* ln (k) *)
+(* ------ *)
+(* N *)
+(* exp *)
+(* *)
+(* 1/N *)
+(* which is equivalent to k *)
+(* *)
+
+var N, k: double;
+
+begin
+ while not eof () do
+ begin
+ readln (N, k);
+ writeln (exp (ln (k) / N) : 1 : 10);
+ end
+end.
diff --git a/challenge-105/abigail/scheme/ch-1.scm b/challenge-105/abigail/scheme/ch-1.scm
new file mode 100644
index 0000000000..41e97c6985
--- /dev/null
+++ b/challenge-105/abigail/scheme/ch-1.scm
@@ -0,0 +1,31 @@
+;;;
+;;; See ../README.md
+;;;
+
+;;;
+;;; Run as: guile --no-auto-compile ch-1.scm < 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.
+;;;
+
+(use-modules (ice-9 format))
+
+(define (nthroot)
+ (define N (read))
+ (if (not (eof-object? N))
+ (begin
+ (format #t "~f\n" (expt (read) (/ 1 N)))
+ (nthroot)
+ )
+ )
+)
+
+(nthroot)