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.119 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.118 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.117 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.116 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.115 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.114 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.113 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.111 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.110 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.109 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.108 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.107 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.106 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.105 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.104 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.103 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.102 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.101 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.100 tracks/common-lisp/exercises/allergies/example.lisp
trackler-2.2.1.99 tracks/common-lisp/exercises/allergies/example.lisp