summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-05 22:23:54 +0530
committerAndinus <andinus@nand.sh>2021-09-05 22:23:54 +0530
commitfec4b82917ccb41362c3170e1b71f9dbf98fb997 (patch)
tree5a9a44dc62fd4e4566a6f963c734d8724de64611
parent670546b8a284bee51f63f00dabcf89b9ea463e68 (diff)
downloadexercism-fec4b82917ccb41362c3170e1b71f9dbf98fb997.tar.gz
Clojure: Raindrops: Add solution
-rw-r--r--clojure/raindrops/HELP.md57
-rw-r--r--clojure/raindrops/README.md42
-rw-r--r--clojure/raindrops/project.clj4
-rw-r--r--clojure/raindrops/src/raindrops.clj15
-rw-r--r--clojure/raindrops/test/raindrops_test.clj51
5 files changed, 169 insertions, 0 deletions
diff --git a/clojure/raindrops/HELP.md b/clojure/raindrops/HELP.md
new file mode 100644
index 0000000..8d93b00
--- /dev/null
+++ b/clojure/raindrops/HELP.md
@@ -0,0 +1,57 @@
+# Help
+
+## Running the tests
+
+Leiningen can be used to run the exercise's test by running the following command from the exercise's directory:
+
+```bash
+lein test
+```
+
+## REPL
+
+To use the REPL to run the exercise's test, run the following command from the exercise's directory:
+
+```bash
+$ lein repl
+```
+
+Then `require` the exercise's test namespace and the Clojure test namespace):
+
+```clojure
+;; replace <exercise> with the exercise's name
+=> (require '<exercise>-test)
+```
+
+Then call `run-tests` on `<exercise>-test`:
+
+```clojure
+;; replace <exercise> with the exercise's name
+=> (clojure.test/run-tests '<exercise>-test)
+```
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit src/raindrops.clj` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [Clojure track's documentation](https://exercism.org/docs/tracks/clojure)
+- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [ClojureDocs](https://clojuredocs.org) A repository of language references and examples by function or keyword.
+- [/r/clojure](https://www.reddit.com/r/clojure) is the C# subreddit.
+- [StackOverflow](http://stackoverflow.com/questions/tagged/clojure) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
\ No newline at end of file
diff --git a/clojure/raindrops/README.md b/clojure/raindrops/README.md
new file mode 100644
index 0000000..6d19b8e
--- /dev/null
+++ b/clojure/raindrops/README.md
@@ -0,0 +1,42 @@
+# Raindrops
+
+Welcome to Raindrops on Exercism's Clojure Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Your task is to convert a number into a string that contains raindrop sounds corresponding to certain potential factors. A factor is a number that evenly divides into another number, leaving no remainder. The simplest way to test if a one number is a factor of another is to use the [modulo operation](https://en.wikipedia.org/wiki/Modulo_operation).
+
+The rules of `raindrops` are that if a given number:
+
+- has 3 as a factor, add 'Pling' to the result.
+- has 5 as a factor, add 'Plang' to the result.
+- has 7 as a factor, add 'Plong' to the result.
+- _does not_ have any of 3, 5, or 7 as a factor, the result should be the digits of the number.
+
+## Examples
+
+- 28 has 7 as a factor, but not 3 or 5, so the result would be "Plong".
+- 30 has both 3 and 5 as factors, but not 7, so the result would be "PlingPlang".
+- 34 is not factored by 3, 5, or 7, so the result would be "34".
+
+## Source
+
+### Created by
+
+- @rubysolo
+
+### Contributed to by
+
+- @AndreaCrotti
+- @canweriotnow
+- @dkinzer
+- @haus
+- @jgwhite
+- @kytrinyx
+- @mathias
+- @yurrriq
+
+### Based on
+
+A variation on FizzBuzz, a famous technical interview question that is intended to weed out potential candidates. That question is itself derived from Fizz Buzz, a popular children's game for teaching division. - https://en.wikipedia.org/wiki/Fizz_buzz
\ No newline at end of file
diff --git a/clojure/raindrops/project.clj b/clojure/raindrops/project.clj
new file mode 100644
index 0000000..65b35f1
--- /dev/null
+++ b/clojure/raindrops/project.clj
@@ -0,0 +1,4 @@
+(defproject raindrops "0.1.0-SNAPSHOT"
+  :description "raindrops exercise."
+  :url "https://github.com/exercism/clojure/tree/master/exercises/raindrops"
+  :dependencies [[org.clojure/clojure "1.10.0"]])
diff --git a/clojure/raindrops/src/raindrops.clj b/clojure/raindrops/src/raindrops.clj
new file mode 100644
index 0000000..8815f2d
--- /dev/null
+++ b/clojure/raindrops/src/raindrops.clj
@@ -0,0 +1,15 @@
+(ns raindrops)
+
+(defn convert [number]
+  (def drops "")
+
+  (if (== (mod number 3) 0)
+    (def drops (str drops "Pling")))
+  (if (== (mod number 5) 0)
+    (def drops (str drops "Plang")))
+  (if (== (mod number 7) 0)
+    (def drops (str drops "Plong")))
+
+  (if (= drops "")
+    (def drops (str number)))
+  drops)
diff --git a/clojure/raindrops/test/raindrops_test.clj b/clojure/raindrops/test/raindrops_test.clj
new file mode 100644
index 0000000..912c887
--- /dev/null
+++ b/clojure/raindrops/test/raindrops_test.clj
@@ -0,0 +1,51 @@
+(ns raindrops-test
+  (:require [clojure.test :refer [deftest is]]
+            raindrops))
+
+(deftest one
+  (is (= "1" (raindrops/convert 1))))
+
+(deftest three
+  (is (= "Pling" (raindrops/convert 3))))
+
+(deftest five
+  (is (= "Plang" (raindrops/convert 5))))
+
+(deftest seven
+  (is (= "Plong" (raindrops/convert 7))))
+
+(deftest six
+  (is (= "Pling" (raindrops/convert 6))))
+
+(deftest nine
+  (is (= "Pling" (raindrops/convert 9))))
+
+(deftest ten
+  (is (= "Plang" (raindrops/convert 10))))
+
+(deftest fourteen
+  (is (= "Plong" (raindrops/convert 14))))
+
+(deftest fifteen
+  (is (= "PlingPlang" (raindrops/convert 15))))
+
+(deftest twenty-one
+  (is (= "PlingPlong" (raindrops/convert 21))))
+
+(deftest twenty-five
+  (is (= "Plang" (raindrops/convert 25))))
+
+(deftest thirty-five
+  (is (= "PlangPlong" (raindrops/convert 35))))
+
+(deftest forty-nine
+  (is (= "Plong" (raindrops/convert 49))))
+
+(deftest fifty-two
+  (is (= "52" (raindrops/convert 52))))
+
+(deftest one-hundred-five
+  (is (= "PlingPlangPlong" (raindrops/convert 105))))
+
+(deftest twelve-thousand-one-hundred-twenty-one
+  (is (= "12121" (raindrops/convert 12121))))