// Package allergies provides allergy related functions.
package allergies
const (
allergyEggs = 1 << iota
allergyPeanuts
allergyShellfish
allergyStrawberries
allergyTomatoes
allergyChocolate
allergyPollen
allergyCats
)
var allergies = []struct {
name string
value uint
}{
{"eggs", allergyEggs},
{"peanuts", allergyPeanuts},
{"shellfish", allergyShellfish},
{"strawberries", allergyStrawberries},
{"tomatoes", allergyTomatoes},
{"chocolate", allergyChocolate},
{"pollen", allergyPollen},
{"cats", allergyCats},
}
// Allergies returs a slice of allergies based on score.
func Allergies(score uint) []string {
out := []string{}
for _, alg := range allergies {
if score&alg.value != 0 {
out = append(out, alg.name)
}
}
return out
}
// AllergicTo returns true if substance is in score. False otherwise.
func AllergicTo(score uint, substance string) bool {
for i := range allergies {
if substance == allergies[i].name &&
score&allergies[i].value != 0 {
return true
}
}
return false
}