Part 2
This commit is contained in:
@@ -47,6 +47,7 @@
|
|||||||
<None Remove="problems\aoc2023\day3\sample.txt" />
|
<None Remove="problems\aoc2023\day3\sample.txt" />
|
||||||
<None Remove="problems\aoc2023\day3\sara.txt" />
|
<None Remove="problems\aoc2023\day3\sara.txt" />
|
||||||
<None Remove="problems\aoc2023\day4\input.txt" />
|
<None Remove="problems\aoc2023\day4\input.txt" />
|
||||||
|
<None Remove="problems\aoc2023\day4\sample.txt" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace AdventOfCode.Problems.AOC2023.Day4;
|
|||||||
internal class Scratchcards : Problem<double, int>
|
internal class Scratchcards : Problem<double, int>
|
||||||
{
|
{
|
||||||
private (int card, int[] win, int[] have)[] _cards = [];
|
private (int card, int[] win, int[] have)[] _cards = [];
|
||||||
|
private Dictionary<int, int> _cardCount = new ();
|
||||||
|
|
||||||
public override void CalculatePart1()
|
public override void CalculatePart1()
|
||||||
{
|
{
|
||||||
@@ -22,7 +23,32 @@ internal class Scratchcards : Problem<double, int>
|
|||||||
|
|
||||||
public override void CalculatePart2()
|
public override void CalculatePart2()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
Part2 = _cards.Length;
|
||||||
|
for (int i = 0; i < _cards.Length; i++)
|
||||||
|
{
|
||||||
|
var card = _cards[i];
|
||||||
|
var wins = card.have.Intersect(card.win).Count();
|
||||||
|
for (int j = 1; j <= wins; j++)
|
||||||
|
AddCards(card.card + j, GetCardCount(card.card));
|
||||||
|
Part2 += wins * GetCardCount(card.card);
|
||||||
|
//_cardCount[card.card] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int GetCardCount(int card)
|
||||||
|
{
|
||||||
|
if(_cardCount.TryGetValue(card, out var count))
|
||||||
|
return count;
|
||||||
|
//_cardCount.Add(card, 1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void AddCards(int card, int count)
|
||||||
|
{
|
||||||
|
if(_cardCount.ContainsKey(card))
|
||||||
|
_cardCount[card] += count;
|
||||||
|
else
|
||||||
|
_cardCount.Add(card, count + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void LoadInput()
|
public override void LoadInput()
|
||||||
|
|||||||
6
AdventOfCode/Problems/AOC2023/Day4/sample.txt
Normal file
6
AdventOfCode/Problems/AOC2023/Day4/sample.txt
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
Card 1: 41 48 83 86 17 | 83 86 6 31 17 9 48 53
|
||||||
|
Card 2: 13 32 20 16 61 | 61 30 68 82 17 32 24 19
|
||||||
|
Card 3: 1 21 53 59 44 | 69 82 63 72 16 21 14 1
|
||||||
|
Card 4: 41 92 73 84 69 | 59 84 76 51 58 5 54 83
|
||||||
|
Card 5: 87 83 26 28 32 | 88 30 70 12 93 22 82 36
|
||||||
|
Card 6: 31 18 13 56 72 | 74 77 10 23 35 67 36 11
|
||||||
Reference in New Issue
Block a user