Sha256: afba23c2849d35db0be0c7325091bd3428bacfae52dcf63bd66d105aa024812d

Contents?: true

Size: 1.25 KB

Versions: 396

Compression:

Stored size: 1.25 KB

Contents

;;; allergies.el --- Allergies Exercise (exercism)

;;; Commentary:

;;; Code:

(require 'cl)

(defvar *allergens-scores*
  '(("eggs" 1)
    ("peanuts" 2)
    ("shellfish" 4)
    ("strawberries" 8)
    ("tomatoes" 16)
    ("chocolate" 32)
    ("pollen" 64)
    ("cats" 128)))

(defun allergen (allergen-and-score)
  "Return allergen from ALLERGEN-AND-SCORE."
  (first allergen-and-score))

(defun score (allergen-and-score)
  "Return score from ALLERGEN-AND-SCORE."
  (second allergen-and-score))

(defun score-matches (allergen-and-score score)
  "Determine if ALLERGEN-AND-SCORE entry match SCORE."
  (not (zerop (logand (score allergen-and-score) score))))

(defun find-all (check seq)
  "Find each match for CHECK in SEQ."
  (remove-if-not check seq))

(defun allergen-list (score)
  "List all allergens with a given SCORE."
  (mapcar 'allergen
          (find-all
           '(lambda (as) (score-matches as score))
           *allergens-scores*)))

(defun allergic-to-p (score allergen)
  "Allergic-to predicate based on SCORE and ALLERGEN."
  (score-matches (cl-assoc allergen *allergens-scores* :test 'string=)
                 score))


(let ((score 1))
 (find-all
  '(lambda (as) (score-matches as score)) *allergens-scores*))

(provide 'allergies)
;;; allergies.el ends here

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.179 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.178 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.177 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.176 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.175 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.174 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.173 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.172 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.171 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.170 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.169 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.167 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.166 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.165 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.164 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.163 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.162 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.161 tracks/elisp/exercises/allergies/example.el
trackler-2.2.1.160 tracks/elisp/exercises/allergies/example.el