ScratchCard.cs 534 B

123456789101112131415161718192021222324
  1. namespace Day4;
  2. public class ScratchCard
  3. {
  4. public int Id { get; }
  5. public ISet<int> Winning { get; } = new HashSet<int>();
  6. public ISet<int> Draw { get; } = new HashSet<int>();
  7. public ScratchCard(int id)
  8. {
  9. Id = id;
  10. }
  11. public int GetMatches()
  12. {
  13. return Draw.Select(draw => Winning.Contains(draw) ? 1 : 0).Sum();
  14. }
  15. public int GetScore()
  16. {
  17. var matches = GetMatches();
  18. return matches > 0 ? (int)Math.Pow(2, matches - 1) : 0;
  19. }
  20. }