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.180 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.179 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.178 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.177 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.176 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.175 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.174 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.173 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.172 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.171 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.170 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.169 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.167 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.166 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.165 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.164 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.163 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.162 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.161 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.160 tracks/common-lisp/exercises/allergies/example.lisp