| 123456789101112131415161718192021222324 |
- namespace Day4;
- public class ScratchCard
- {
- public int Id { get; }
- public ISet<int> Winning { get; } = new HashSet<int>();
- public ISet<int> Draw { get; } = new HashSet<int>();
- public ScratchCard(int id)
- {
- Id = id;
- }
-
- public int GetMatches()
- {
- return Draw.Select(draw => Winning.Contains(draw) ? 1 : 0).Sum();
- }
- public int GetScore()
- {
- var matches = GetMatches();
- return matches > 0 ? (int)Math.Pow(2, matches - 1) : 0;
- }
- }
|