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