Created
May 14, 2024 03:47
-
-
Save DrunkenAlcoholic/35944a717919f9b07e9797dcd0db2741 to your computer and use it in GitHub Desktop.
Allergies [Exercism - Nim]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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