Sha256: c105ce6723ea3f5f86c2899c96a7e575adcf69c821e071ddc9cf9a5fb8248dac
Contents?: true
Size: 938 Bytes
Versions: 208
Compression:
Stored size: 938 Bytes
Contents
using System.Collections.Generic; using System.Linq; public class Allergies { private readonly int score; private static readonly Dictionary<string, int> AvailableAllergies = new Dictionary<string, int> { { "eggs", 1 }, { "peanuts", 2 }, { "shellfish", 4 }, { "strawberries", 8 }, { "tomatoes", 16 }, { "chocolate", 32 }, { "pollen", 64 }, { "cats", 128 } }; public Allergies(int score) { this.score = score; } public bool AllergicTo(string allergy) { return IsInAllergyScore(AvailableAllergies[allergy]); } public IList<string> List() { return AvailableAllergies.Where(x => IsInAllergyScore(x.Value)).Select(x => x.Key).ToList(); } private bool IsInAllergyScore(int allergyValue) { return (score & allergyValue) == allergyValue; } }
Version data entries
208 entries across 208 versions & 1 rubygems