2016-05-13 02:26:52 +00:00
|
|
|
module Allergies exposing (..)
|
2016-03-27 01:08:15 +00:00
|
|
|
|
|
|
|
import List
|
|
|
|
import Bitwise
|
|
|
|
|
|
|
|
|
|
|
|
isAllergicTo : String -> Int -> Bool
|
|
|
|
isAllergicTo name score =
|
2016-06-19 21:46:13 +00:00
|
|
|
List.member name (toList score)
|
2016-03-27 01:08:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
toList : Int -> List String
|
|
|
|
toList score =
|
2016-06-19 21:46:13 +00:00
|
|
|
allergies
|
|
|
|
|> List.indexedMap (\i n -> ( Bitwise.shiftLeft 1 i, n ))
|
|
|
|
|> List.filter (\( s, n ) -> Bitwise.and s score > 0)
|
|
|
|
|> List.map snd
|
2016-03-27 01:08:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
allergies : List String
|
|
|
|
allergies =
|
2016-06-19 21:46:13 +00:00
|
|
|
[ "eggs"
|
|
|
|
, "peanuts"
|
|
|
|
, "shellfish"
|
|
|
|
, "strawberries"
|
|
|
|
, "tomatoes"
|
|
|
|
, "chocolate"
|
|
|
|
, "pollen"
|
|
|
|
, "cats"
|
|
|
|
]
|