Sha256: 46a54c294405b647a36d7a14cee1266bdabc2954549d0f7e229d120c306c88db

Contents?: true

Size: 939 Bytes

Versions: 396

Compression:

Stored size: 939 Bytes

Contents

(defpackage #:allergies
  (:use #:common-lisp)
  (:shadow #:list)
  (:export #:allergic-to-p #:list))

(in-package #:allergies)

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

(defun allergen (allergen-and-score) (first allergen-and-score))
(defun score (allergen-and-score) (second allergen-and-score))

(defun score-matches (allergen-and-score score)
  (not (zerop (logand (score allergen-and-score) score))))

(defun find-all (test sequence)
  (loop for i in sequence
     when (funcall test i) collecting i))

(defun list (score)
  (mapcar #'allergen
          (find-all
           #'(lambda (as) (score-matches as score))
           *allergens-scores*)))

(defun allergic-to-p (score allergen)
  (score-matches (assoc allergen *allergens-scores* :test #'string-equal)
                 score))

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.138 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.137 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.136 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.135 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.134 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.133 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.132 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.131 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.130 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.129 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.128 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.127 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.126 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.125 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.124 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.123 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.122 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.121 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.120 tracks/common-lisp/exercises/allergies/example.lisp