Sha256: a96e20b809b6aaf2b4d7305967f910ef58f09ea84a5f0daaa00539d63473ca39
Contents?: true
Size: 859 Bytes
Versions: 396
Compression:
Stored size: 859 Bytes
Contents
(defmodule allergies (export (allergies 1) (allergic-to? 2))) (defmacro ALLERGIES () `'(eggs ; 2^0 peanuts ; 2^1 shellfish ; 2^2 strawberries ; 2^3 tomatoes chocolate pollen cats)) (defun allergies (score) (lists:filter (lambda (allergen) (allergic-to? allergen score)) (ALLERGIES))) (defun allergic-to? (allergen score) (let ((index (index-of allergen (ALLERGIES)))) (andalso (=/= 'not-found index) (> (band score (trunc (math:pow 2 index))) 0.0)))) (defun index-of (allergen allergies) (index 0 allergies allergen)) (defun index ([index (cons allergen* _) allergen] (when (=:= allergen* allergen)) index) ([index (cons _ allergies) allergen] (index (+ index 1) allergies allergen)) ([_ () _] 'not-found))
Version data entries
396 entries across 396 versions & 1 rubygems