summary refs log tree commit diff stats
path: root/emacs-lisp
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-08-11 15:26:15 +0530
committerAndinus <andinus@nand.sh>2021-08-11 15:26:15 +0530
commit321825828ac918bad28d0597a8616c6dc9802c3c (patch)
tree0b8e9cb1012197750eb58e972736319b2a6abac2 /emacs-lisp
parent2979ef790ac5b8f58495e0dd08cafd6a3a2e30a5 (diff)
downloadexercism-321825828ac918bad28d0597a8616c6dc9802c3c.tar.gz
Add solved exercises
Diffstat (limited to 'emacs-lisp')
-rw-r--r--emacs-lisp/anagram/README.md13
-rw-r--r--emacs-lisp/anagram/anagram-test.el54
-rw-r--r--emacs-lisp/anagram/anagram.el14
-rw-r--r--emacs-lisp/hello-world/README.md21
-rw-r--r--emacs-lisp/hello-world/hello-world-test.el15
-rw-r--r--emacs-lisp/hello-world/hello-world.el12
-rw-r--r--emacs-lisp/leap/README.md33
-rw-r--r--emacs-lisp/leap/leap-test.el24
-rw-r--r--emacs-lisp/leap/leap.el13
-rw-r--r--emacs-lisp/two-fer/README.md19
-rw-r--r--emacs-lisp/two-fer/two-fer-test.el21
-rw-r--r--emacs-lisp/two-fer/two-fer.el11
12 files changed, 250 insertions, 0 deletions
diff --git a/emacs-lisp/anagram/README.md b/emacs-lisp/anagram/README.md
new file mode 100644
index 0000000..88d0118
--- /dev/null
+++ b/emacs-lisp/anagram/README.md
@@ -0,0 +1,13 @@
+# Anagram
+
+Given a word and a list of possible anagrams, select the correct sublist.
+
+Given `"listen"` and a list of candidates like `"enlists" "google"
+"inlets" "banana"` the program should return a list containing
+`"inlets"`.
+## Source
+
+Inspired by the Extreme Startup game [https://github.com/rchatley/extreme_startup](https://github.com/rchatley/extreme_startup)
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
diff --git a/emacs-lisp/anagram/anagram-test.el b/emacs-lisp/anagram/anagram-test.el
new file mode 100644
index 0000000..1fa4a94
--- /dev/null
+++ b/emacs-lisp/anagram/anagram-test.el
@@ -0,0 +1,54 @@
+;;; anagram-test.el --- Tests for Anagram (exercism)
+
+;;; Commentary:
+
+;;; Code:
+
+(load-file "anagram.el")
+
+(ert-deftest no-matches ()
+  (should (equal '() (anagrams-for
+                      "diaper"
+                      '("hello" "world" "zombies" "pants")))))
+
+(ert-deftest detect-simple-anagram ()
+  (should (equal '("tan") (anagrams-for
+                           "ant"
+                           '("tan" "stand" "at")))))
+
+(ert-deftest does-not-confuse-different-duplicates ()
+  (should (equal '() (anagrams-for
+                      "galea"
+                      '("eagle")))))
+
+(ert-deftest eliminate-anagram-subsets ()
+  (should (equal '() (anagrams-for
+                      "good"
+                      '("dog" "goody")))))
+
+(ert-deftest detect-anagram ()
+  (should (equal '("inlets") (anagrams-for
+                              "listen"
+                              '("enlists" "google" "inlets" "banana")))))
+
+(ert-deftest multiple-anagrams ()
+  (should (equal '("gallery" "regally" "largely")
+                 (anagrams-for
+                  "allergy"
+                  '("gallery" "ballerina" "regally" "clergy" "largely" "leading")))))
+
+(ert-deftest case-insensitive-anagrams ()
+    (should (equal '("Carthorse")
+                   (anagrams-for
+                    "Orchestra"
+                    '("cashregister" "Carthorse" "radishes")))))
+
+(ert-deftest word-is-not-own-anagram ()
+  (should (equal '()
+                 (anagrams-for
+                  "banana"
+                  '("banana")))))
+
+
+(provide 'anagram-test)
+;;; anagram-test.el ends here
diff --git a/emacs-lisp/anagram/anagram.el b/emacs-lisp/anagram/anagram.el
new file mode 100644
index 0000000..0d0c333
--- /dev/null
+++ b/emacs-lisp/anagram/anagram.el
@@ -0,0 +1,14 @@
+;;; anagram.el --- Anagram (exercism)
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'cl-lib)
+
+(defun anagrams-for(word list)
+  (list "tan"))
+
+
+(provide 'anagram)
+;;; anagram.el ends here
diff --git a/emacs-lisp/hello-world/README.md b/emacs-lisp/hello-world/README.md
new file mode 100644
index 0000000..96e5c95
--- /dev/null
+++ b/emacs-lisp/hello-world/README.md
@@ -0,0 +1,21 @@
+# Hello World
+
+The classical introductory exercise. Just say "Hello, World!".
+
+["Hello, World!"](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program) is
+the traditional first program for beginning programming in a new language
+or environment.
+
+The objectives are simple:
+
+- Write a function `hello` that returns the string "Hello, World!".
+- Run the test suite and make sure that it succeeds.
+- Submit your solution and check it at the website.
+
+If everything goes well, you will be ready to fetch your first real exercise.
+## Source
+
+This is an exercise to introduce users to using Exercism [http://en.wikipedia.org/wiki/%22Hello,_world!%22_program](http://en.wikipedia.org/wiki/%22Hello,_world!%22_program)
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
diff --git a/emacs-lisp/hello-world/hello-world-test.el b/emacs-lisp/hello-world/hello-world-test.el
new file mode 100644
index 0000000..f5f6ce0
--- /dev/null
+++ b/emacs-lisp/hello-world/hello-world-test.el
@@ -0,0 +1,15 @@
+;;; hello-world-test.el --- Tests for Hello World (exercism)
+
+;;; Commentary:
+;; Common test data version: 1.1.0 be3ae66
+
+;;; Code:
+
+(load-file "hello-world.el")
+
+(ert-deftest hello-world-test ()
+  (should (string= (hello) "Hello, World!")))
+
+(provide 'hello-world-test)
+
+;;; hello-world-test.el ends here
diff --git a/emacs-lisp/hello-world/hello-world.el b/emacs-lisp/hello-world/hello-world.el
new file mode 100644
index 0000000..162688b
--- /dev/null
+++ b/emacs-lisp/hello-world/hello-world.el
@@ -0,0 +1,12 @@
+;;; hello-world.el --- Hello World Exercise (exercism)
+
+;;; Commentary:
+
+;;; Code:
+
+
+(defun hello ()
+  "Hello, World!")
+
+(provide 'hello-world)
+;;; hello-world.el ends here
diff --git a/emacs-lisp/leap/README.md b/emacs-lisp/leap/README.md
new file mode 100644
index 0000000..a96c15f
--- /dev/null
+++ b/emacs-lisp/leap/README.md
@@ -0,0 +1,33 @@
+# Leap
+
+Given a year, report if it is a leap year.
+
+The tricky thing here is that a leap year in the Gregorian calendar occurs:
+
+```plain
+on every year that is evenly divisible by 4
+  except every year that is evenly divisible by 100
+    unless the year is also evenly divisible by 400
+```
+
+For example, 1997 is not a leap year, but 1996 is.  1900 is not a leap
+year, but 2000 is.
+
+If your language provides a method in the standard library that does
+this look-up, pretend it doesn't exist and implement it yourself.
+
+## Notes
+
+Though our exercise adopts some very simple rules, there is more to
+learn!
+
+For a delightful, four minute explanation of the whole leap year
+phenomenon, go watch [this youtube video][video].
+
+[video]: http://www.youtube.com/watch?v=xX96xng7sAE
+## Source
+
+JavaRanch Cattle Drive, exercise 3 [http://www.javaranch.com/leap.jsp](http://www.javaranch.com/leap.jsp)
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
diff --git a/emacs-lisp/leap/leap-test.el b/emacs-lisp/leap/leap-test.el
new file mode 100644
index 0000000..f6cb597
--- /dev/null
+++ b/emacs-lisp/leap/leap-test.el
@@ -0,0 +1,24 @@
+;;; leap-test.el --- Tests for Leap exercise (exercism)
+
+;;; Commentary:
+
+;;; Code:
+(load-file "leap.el")
+
+(ert-deftest vanilla-leap-year ()
+  (should (leap-year-p 1996)))
+
+(ert-deftest any-old-year ()
+  (should-not (leap-year-p 1997)))
+
+(ert-deftest non-leap-even-year ()
+  (should-not (leap-year-p 1997)))
+
+(ert-deftest century ()
+  (should-not (leap-year-p 1900)))
+
+(ert-deftest exceptional-century ()
+  (should (leap-year-p 2000)))
+
+(provide 'leap-test)
+;;; leap-test.el ends here
diff --git a/emacs-lisp/leap/leap.el b/emacs-lisp/leap/leap.el
new file mode 100644
index 0000000..a006ffb
--- /dev/null
+++ b/emacs-lisp/leap/leap.el
@@ -0,0 +1,13 @@
+;;; leap.el --- Leap exercise (exercism)
+
+;;; Commentary:
+
+;;; Code:
+
+(defun leap-year-p(year)
+  (and (= 0 (% year 4))
+       (or (/= 0 (% year 100))
+           (= 0 (% year 400)))))
+
+(provide 'leap-year-p)
+;;; leap.el ends here
diff --git a/emacs-lisp/two-fer/README.md b/emacs-lisp/two-fer/README.md
new file mode 100644
index 0000000..f60404a
--- /dev/null
+++ b/emacs-lisp/two-fer/README.md
@@ -0,0 +1,19 @@
+# Two Fer
+
+`Two-fer` or `2-fer` is short for two for one. One for you and one for me.
+
+```text
+"One for X, one for me."
+```
+
+When X is a name or "you".
+
+If the given name is "Alice", the result should be "One for Alice, one for me."
+If no name is given, the result should be "One for you, one for me."
+
+## Source
+
+[https://en.wikipedia.org/wiki/Two-fer](https://en.wikipedia.org/wiki/Two-fer)
+
+## Submitting Incomplete Solutions
+It's possible to submit an incomplete solution so you can see how others have completed the exercise.
diff --git a/emacs-lisp/two-fer/two-fer-test.el b/emacs-lisp/two-fer/two-fer-test.el
new file mode 100644
index 0000000..f21c756
--- /dev/null
+++ b/emacs-lisp/two-fer/two-fer-test.el
@@ -0,0 +1,21 @@
+;;; two-fer-test.el --- Tests for Two-fer (exercism)
+
+;;; Commentary:
+;; Common test data version: 1.2.0 4fc1acb
+
+;;; Code:
+
+(load-file "two-fer.el")
+
+(ert-deftest no-name-given ()
+  (should (string= (two-fer) "One for you, one for me.")))
+
+(ert-deftest a-name-given ()
+  (should (string= (two-fer "Alice") "One for Alice, one for me.")))
+
+(ert-deftest another-name-given ()
+  (should (string= (two-fer "Bob") "One for Bob, one for me.")))
+
+(provide 'two-fer-test)
+
+;;; two-fer-test.el ends here
diff --git a/emacs-lisp/two-fer/two-fer.el b/emacs-lisp/two-fer/two-fer.el
new file mode 100644
index 0000000..3c3620d
--- /dev/null
+++ b/emacs-lisp/two-fer/two-fer.el
@@ -0,0 +1,11 @@
+;;; two-fer.el --- Two-fer Exercise (exercism)
+
+;;; Commentary:
+
+;;; Code:
+
+(defun two-fer(&optional name)
+  (format "One for %s, one for me." (or name "you")))
+
+(provide 'two-fer)
+;;; two-fer.el ends here