Sha256: ced6a5895a6e27d9e3cd9871485909e9e8bda7e329e758fa110bd6af48b52ee7
Contents?: true
Size: 940 Bytes
Versions: 188
Compression:
Stored size: 940 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 IsAllergicTo(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
188 entries across 188 versions & 1 rubygems