aboutsummaryrefslogtreecommitdiff
path: root/challenge-001
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.freedom.nl>2022-01-04 20:30:55 +0100
committerAbigail <abigail@abigail.freedom.nl>2022-01-04 20:30:55 +0100
commit98aa56c2999d92040ae56d744d83eaee5f97b208 (patch)
treea4eb2dfaeb4942f0aa935878afa30c2532022a03 /challenge-001
parenta195125ca7f99c50965953e6c02a8557a4039b4a (diff)
downloadperlweeklychallenge-club-98aa56c2999d92040ae56d744d83eaee5f97b208.tar.gz
perlweeklychallenge-club-98aa56c2999d92040ae56d744d83eaee5f97b208.tar.bz2
perlweeklychallenge-club-98aa56c2999d92040ae56d744d83eaee5f97b208.zip
Week 1: R solutions
Diffstat (limited to 'challenge-001')
-rw-r--r--challenge-001/abigail/README.md2
-rw-r--r--challenge-001/abigail/r/ch-1.r19
-rw-r--r--challenge-001/abigail/r/ch-2.r33
3 files changed, 54 insertions, 0 deletions
diff --git a/challenge-001/abigail/README.md b/challenge-001/abigail/README.md
index a049b3a647..1d8ab34070 100644
--- a/challenge-001/abigail/README.md
+++ b/challenge-001/abigail/README.md
@@ -23,6 +23,7 @@ count the number of time we encountered an 'e'.
* [Pascal](pascal/ch-1.p)
* [Perl](perl/ch-1.pl)
* [Python](python/ch-1.py)
+* [R](r/ch-1.r)
* [Ruby](ruby/ch-1.rb)
@@ -50,4 +51,5 @@ upper bound from STDIN.
* [Pascal](pascal/ch-2.p)
* [Perl](perl/ch-2.pl)
* [Python](python/ch-2.py)
+* [R](r/ch-2.r)
* [Ruby](ruby/ch-2.rb)
diff --git a/challenge-001/abigail/r/ch-1.r b/challenge-001/abigail/r/ch-1.r
new file mode 100644
index 0000000000..13bc4f276b
--- /dev/null
+++ b/challenge-001/abigail/r/ch-1.r
@@ -0,0 +1,19 @@
+#!/usr/local/bin/Rscript
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-001
+#
+
+#
+# Run as: Rscript ch-1.r < input-file
+#
+
+stdin <- file ('stdin', 'r')
+repeat {
+ line <- readLines (stdin, n = 1)
+ if (length (line) == 0) {
+ break
+ }
+ cat (gsub ("e", "E", line), "\n")
+ cat (nchar (gsub ("[^e]", "", line)), "\n")
+}
diff --git a/challenge-001/abigail/r/ch-2.r b/challenge-001/abigail/r/ch-2.r
new file mode 100644
index 0000000000..0796577877
--- /dev/null
+++ b/challenge-001/abigail/r/ch-2.r
@@ -0,0 +1,33 @@
+#!/usr/local/bin/Rscript
+
+#
+# See https://theweeklychallenge.org/blog/perl-weekly-challenge-001
+#
+
+#
+# Run as: Rscript ch-2.r < input-file
+#
+
+stdin <- file ('stdin', 'r')
+repeat {
+ max <- readLines (stdin, n = 1)
+ if (length (max) == 0) {
+ break
+ }
+ max = as.integer (max)
+ for (i in 1 : max) {
+ if (i %% 15 == 0) {
+ cat ("fizzbuzz\n")
+ next
+ }
+ if (i %% 5 == 0) {
+ cat ( "buzz\n")
+ next
+ }
+ if (i %% 3 == 0) {
+ cat ("fizz\n" )
+ next
+ }
+ cat (i, "\n")
+ }
+}