aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-112/abigail/README.md1
-rw-r--r--challenge-112/abigail/r/ch-2.r20
2 files changed, 21 insertions, 0 deletions
diff --git a/challenge-112/abigail/README.md b/challenge-112/abigail/README.md
index ea6f9e783a..da117ffa47 100644
--- a/challenge-112/abigail/README.md
+++ b/challenge-112/abigail/README.md
@@ -67,6 +67,7 @@ This is just finding the `$n + 1` Fibonacci number.
* [Perl](perl/ch-2.pl)
* [Pascal](pascal/ch-2.p)
* [Python](python/ch-2.py)
+* [R](r/ch-2.r)
* [Ruby](ruby/ch-2.rb)
* [Scheme](scheme/ch-2.scm)
diff --git a/challenge-112/abigail/r/ch-2.r b/challenge-112/abigail/r/ch-2.r
new file mode 100644
index 0000000000..4d1fd9db6d
--- /dev/null
+++ b/challenge-112/abigail/r/ch-2.r
@@ -0,0 +1,20 @@
+#
+# See ../README.md
+#
+
+#
+# Run as: Rscript ch-2.r < input-file
+#
+
+stdin <- file ('stdin', 'r')
+
+sqrt5 <- sqrt (5)
+phi <- (1 + sqrt5) / 2
+
+repeat {
+ n <- readLines (stdin, n = 1)
+ if (length (n) == 0) {
+ break
+ }
+ cat (round (phi ^ (as.integer (n) + 1) / sqrt5), "\n", sep = "")
+}