mirror of
https://github.com/correl/elm.git
synced 2024-11-16 19:19:28 +00:00
31 lines
509 B
Text
31 lines
509 B
Text
|
module Allergies (..) where
|
||
|
|
||
|
import List
|
||
|
import Bitwise
|
||
|
|
||
|
|
||
|
isAllergicTo : String -> Int -> Bool
|
||
|
isAllergicTo name score =
|
||
|
List.member name (toList score)
|
||
|
|
||
|
|
||
|
toList : Int -> List String
|
||
|
toList score =
|
||
|
allergies
|
||
|
|> List.indexedMap (\i n -> ( Bitwise.shiftLeft 1 i, n ))
|
||
|
|> List.filter (\( s, n ) -> Bitwise.and s score > 0)
|
||
|
|> List.map snd
|
||
|
|
||
|
|
||
|
allergies : List String
|
||
|
allergies =
|
||
|
[ "eggs"
|
||
|
, "peanuts"
|
||
|
, "shellfish"
|
||
|
, "strawberries"
|
||
|
, "tomatoes"
|
||
|
, "chocolate"
|
||
|
, "pollen"
|
||
|
, "cats"
|
||
|
]
|