Skip to content

Instantly share code, notes, and snippets.

@DrunkenAlcoholic
Created May 14, 2024 03:47
Show Gist options
  • Save DrunkenAlcoholic/35944a717919f9b07e9797dcd0db2741 to your computer and use it in GitHub Desktop.
Save DrunkenAlcoholic/35944a717919f9b07e9797dcd0db2741 to your computer and use it in GitHub Desktop.
Allergies [Exercism - Nim]
type
Allergen* = enum
Eggs, Peanuts, Shellfish, Strawberries, Tomatoes, Chocolate, Pollen, Cats
proc isAllergicTo*(score: int, allergen: Allergen): bool =
let allergenScore = 1 shl ord(allergen)
return (score and allergenScore) != 0
proc allergies*(score: int): set[Allergen] =
result = {}
for allergen in Allergen:
let allergenScore = 1 shl ord(allergen)
if (score and allergenScore) != 0:
result.incl(allergen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment