Sha256: fb94a2e48d04175f5ae0c9e3a8f8afd7c9f828ee1b4d6928dabd3a80ec5b7f1e
Contents?: true
Size: 620 Bytes
Versions: 274
Compression:
Stored size: 620 Bytes
Contents
package allergies import "math" const testVersion = 1 var allergens = []string{"eggs", "peanuts", "shellfish", "strawberries", "tomatoes", "chocolate", "pollen", "cats"} func Allergies(i uint) (result []string) { for _, v := range allergens { if AllergicTo(i, v) { result = append(result, []string{v}...) } } return result } func AllergicTo(i uint, allergen string) bool { index := indexOf(allergens, allergen) x := uint(math.Pow(2.0, float64(index))) return (i & x) > 0 } func indexOf(slice []string, string string) int { for p, v := range slice { if v == string { return p } } return -1 }
Version data entries
274 entries across 274 versions & 1 rubygems