summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Orbekk <kj@orbekk.com>2021-11-25 12:05:00 -0500
committerKjetil Orbekk <kj@orbekk.com>2021-11-25 12:05:00 -0500
commitde7be7341cfe5105ee01824bb8108dcb84b6d115 (patch)
tree6bfc6d5872ee2cb9e25f356db5840e97ff885eb1
parentd655a8498c45209478a7933b05ad49f3863a345d (diff)
allergies exercise
-rw-r--r--exercism/emacs-lisp/allergies/.exercism/config.json22
-rw-r--r--exercism/emacs-lisp/allergies/.exercism/metadata.json1
-rw-r--r--exercism/emacs-lisp/allergies/HELP.md41
-rw-r--r--exercism/emacs-lisp/allergies/README.md49
-rw-r--r--exercism/emacs-lisp/allergies/allergies-test.el53
-rw-r--r--exercism/emacs-lisp/allergies/allergies.el32
6 files changed, 198 insertions, 0 deletions
diff --git a/exercism/emacs-lisp/allergies/.exercism/config.json b/exercism/emacs-lisp/allergies/.exercism/config.json
new file mode 100644
index 0000000..944e79c
--- /dev/null
+++ b/exercism/emacs-lisp/allergies/.exercism/config.json
@@ -0,0 +1,22 @@
+{
+ "blurb": "Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.",
+ "authors": [
+ "canweriotnow"
+ ],
+ "contributors": [
+ "vermiculus"
+ ],
+ "files": {
+ "solution": [
+ "allergies.el"
+ ],
+ "test": [
+ "allergies-test.el"
+ ],
+ "example": [
+ ".meta/example.el"
+ ]
+ },
+ "source": "Jumpstart Lab Warm-up",
+ "source_url": "http://jumpstartlab.com"
+}
diff --git a/exercism/emacs-lisp/allergies/.exercism/metadata.json b/exercism/emacs-lisp/allergies/.exercism/metadata.json
new file mode 100644
index 0000000..17c6ae9
--- /dev/null
+++ b/exercism/emacs-lisp/allergies/.exercism/metadata.json
@@ -0,0 +1 @@
+{"track":"emacs-lisp","exercise":"allergies","id":"5dd190c7e48f450e98a30275be375ce5","url":"https://exercism.org/tracks/emacs-lisp/exercises/allergies","handle":"orbekk","is_requester":true,"auto_approve":false} \ No newline at end of file
diff --git a/exercism/emacs-lisp/allergies/HELP.md b/exercism/emacs-lisp/allergies/HELP.md
new file mode 100644
index 0000000..aabf8fd
--- /dev/null
+++ b/exercism/emacs-lisp/allergies/HELP.md
@@ -0,0 +1,41 @@
+# Help
+
+## Running the tests
+
+Tests can be run several ways:
+
+1. Interactively and individually, with `M-x ert RET test-name RET`
+2. Interactively and all at once, with `M-x ert RET t RET`
+3. From the terminal, in batch mode, with `emacs -batch -l ert -l my-test.el -f ert-run-tests-batch-and-exit`
+4. Other options can be found in the docs, `C-h i m ert RET`
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit allergies.el` 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 [Emacs Lisp track's documentation](https://exercism.org/docs/tracks/emacs-lisp)
+- [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:
+
+- [The Emacs Wiki](http://emacswiki.org/) is invaluable. Spend lots of time here.
+- [The Emacs Editor](http://www.gnu.org/software/emacs/manual/html_node/emacs/index.html) is the official manual for GNU Emacs.
+- IRC - there are [freenode](https://freenode.net/) channels for `#emacs`, `#prelude`, and many Emacs
+ packages, and many helpful folks around. And with emacs, IRC is as close as
+ `M-x erc`.
+- [Exercism Support](https://gitter.im/exercism/support) Gitter chat is also a good place to get help from the
+ exercism community.
+- [StackOverflow](http://stackoverflow.com/questions/tagged/elisp) 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/exercism/emacs-lisp/allergies/README.md b/exercism/emacs-lisp/allergies/README.md
new file mode 100644
index 0000000..6dd4899
--- /dev/null
+++ b/exercism/emacs-lisp/allergies/README.md
@@ -0,0 +1,49 @@
+# Allergies
+
+Welcome to Allergies on Exercism's Emacs Lisp Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+Given a person's allergy score, determine whether or not they're allergic to a given item, and their full list of allergies.
+
+An allergy test produces a single numeric score which contains the
+information about all the allergies the person has (that they were
+tested for).
+
+The list of items (and their value) that were tested are:
+
+* eggs (1)
+* peanuts (2)
+* shellfish (4)
+* strawberries (8)
+* tomatoes (16)
+* chocolate (32)
+* pollen (64)
+* cats (128)
+
+So if Tom is allergic to peanuts and chocolate, he gets a score of 34.
+
+Now, given just that score of 34, your program should be able to say:
+
+- Whether Tom is allergic to any one of those allergens listed above.
+- All the allergens Tom is allergic to.
+
+Note: a given score may include allergens **not** listed above (i.e.
+allergens that score 256, 512, 1024, etc.). Your program should
+ignore those components of the score. For example, if the allergy
+score is 257, your program should only report the eggs (1) allergy.
+
+## Source
+
+### Created by
+
+- @canweriotnow
+
+### Contributed to by
+
+- @vermiculus
+
+### Based on
+
+Jumpstart Lab Warm-up - http://jumpstartlab.com \ No newline at end of file
diff --git a/exercism/emacs-lisp/allergies/allergies-test.el b/exercism/emacs-lisp/allergies/allergies-test.el
new file mode 100644
index 0000000..6ae3bb9
--- /dev/null
+++ b/exercism/emacs-lisp/allergies/allergies-test.el
@@ -0,0 +1,53 @@
+;;; allergies-test.el --- Tests for Allergies (exercism)
+
+;;; Commentary:
+
+;;; Code:
+
+(load-file "allergies.el")
+
+(ert-deftest no-allergies-at-all ()
+ (should (equal '() (allergen-list 0))))
+
+(ert-deftest allergic-to-just-eggs ()
+ (should (equal '("eggs") (allergen-list 1))))
+
+(ert-deftest allergic-to-just-peanuts ()
+ (should (equal '("peanuts") (allergen-list 2))))
+
+(ert-deftest allergic-to-just-strawberries ()
+ (should (equal '("strawberries") (allergen-list 8))))
+
+(ert-deftest allergic-to-eggs-and-peanuts ()
+ (should (equal '("eggs" "peanuts") (allergen-list 3))))
+
+(ert-deftest allergic-to-more-than-eggs-but-not-peanuts ()
+ (should (equal '("eggs" "shellfish") (allergen-list 5))))
+
+(ert-deftest allergic-to-lots-of-stuff ()
+ (should (equal '("strawberries" "tomatoes" "chocolate" "pollen" "cats")
+ (allergen-list 248))))
+
+(ert-deftest allergic-to-everything ()
+ (should (equal '("eggs" "peanuts" "shellfish" "strawberries" "tomatoes"
+ "chocolate" "pollen" "cats")
+ (allergen-list 255))))
+
+(ert-deftest no-allergies-means-not-allergic ()
+ (should-not (allergic-to-p 0 "peanuts"))
+ (should-not (allergic-to-p 0 "cats"))
+ (should-not (allergic-to-p 0 "strawberries")))
+
+(ert-deftest is-allergic-to-eggs ()
+ (should (allergic-to-p 1 "eggs")))
+
+(ert-deftest allergic-to-eggs-and-other-stuff ()
+ (should (allergic-to-p 5 "eggs")))
+
+(ert-deftest ignore-non-allergen-score-parts ()
+ (should (equal '("eggs" "shellfish" "strawberries" "tomatoes"
+ "chocolate" "pollen" "cats")
+ (allergen-list 509))))
+
+(provide 'allergies)
+;;; allergies-test.el ends here
diff --git a/exercism/emacs-lisp/allergies/allergies.el b/exercism/emacs-lisp/allergies/allergies.el
new file mode 100644
index 0000000..1279484
--- /dev/null
+++ b/exercism/emacs-lisp/allergies/allergies.el
@@ -0,0 +1,32 @@
+;;; allergies.el --- Allergies Exercise (exercism)
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'seq)
+
+(setq allergens
+ '(eggs
+ peanuts
+ shellfish
+ strawberries
+ tomatoes
+ chocolate
+ pollen
+ cats))
+
+(defun allergen-list (n)
+ (let* ((index 0)
+ (pred (lambda (item)
+ (let ((r (< 0 (logand (ash 1 index) n))))
+ (setq index (1+ index))
+ (when r item)))))
+ (mapcar 'symbol-name
+ (seq-filter pred allergens))))
+
+(defun allergic-to-p (n item)
+ (seq-contains-p (allergen-list n) item))
+
+(provide 'allergies)
+;;; allergies.el ends here