From 343f1f08ba25319ff30e58d46892a20c90060f5c Mon Sep 17 00:00:00 2001 From: TiagoRG Date: Tue, 5 Dec 2023 17:22:28 +0000 Subject: [PATCH] [2023] Update Day4 Signed-off-by: TiagoRG --- Year2023/Day4.cs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Year2023/Day4.cs b/Year2023/Day4.cs index 2a46647..8774a30 100644 --- a/Year2023/Day4.cs +++ b/Year2023/Day4.cs @@ -7,8 +7,6 @@ public static class Day4 private class Card { public int CardNumber { get; set; } - public int[]? WinningNumbers { get; set; } - public int[]? Numbers { get; set; } public int ValidNumbers { get; set; } } @@ -22,15 +20,11 @@ public static class Day4 Card card = new Card(); card.CardNumber = Convert.ToInt32(Regex.Split(line.Split(": ")[0], @"\s+").Last()); string[] cardNumbers = Regex.Split(line.Split(": ")[1], @"\s+\|\s+"); - card.WinningNumbers = Regex.Split(cardNumbers.First(), @"\W+").Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToArray(); - card.Numbers = Regex.Split(cardNumbers.Last(), @"\W+").Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToArray(); - Cards.Add(card); - }); - - Cards.ForEach(card => - { + int[] winningNumbers = Regex.Split(cardNumbers.First(), @"\W+").Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToArray(); + int[] numbers = Regex.Split(cardNumbers.Last(), @"\W+").Where(x => !string.IsNullOrEmpty(x)).Select(x => Convert.ToInt32(x)).ToArray(); card.ValidNumbers = 0; - card.Numbers!.ToList().ForEach(number => card.ValidNumbers += card.WinningNumbers!.Contains(number) ? 1 : 0); + numbers.ToList().ForEach(number => card.ValidNumbers += winningNumbers.Contains(number) ? 1 : 0); + Cards.Add(card); }); Console.WriteLine($@"