public void Part2() { int[] rollOutcomes = new int[] { 0, 0, 0, 1, 3, 6, 7, 6, 3, 1 }; long p1Wins = 0; long p2Wins = 0; Queue <DiceGame> inProgressGames = new Queue <DiceGame>() { }; inProgressGames.Enqueue(ReadGameFromFile()); while (inProgressGames.Count > 0) { DiceGame previousRound = inProgressGames.Dequeue(); for (int p1Roll = 3; p1Roll < 10; p1Roll++) { DiceGame p1Round = previousRound.Player1Rolls(p1Roll, rollOutcomes[p1Roll]); if (p1Round.IsComplete(21)) { p1Wins += p1Round.Combos; continue; } for (int p2Roll = 3; p2Roll < 10; p2Roll++) { DiceGame p2Round = p1Round.Player2Rolls(p2Roll, rollOutcomes[p2Roll]); if (p2Round.IsComplete(21)) { p2Wins += p2Round.Combos; continue; } inProgressGames.Enqueue(p2Round); } } } long result = Math.Max(p1Wins, p2Wins); Assert.Equal(48868319769358, result); }
public void Part1() { DiceGame game = ReadGameFromFile(); int timesRolled = 0; int NextRoll() { int rollSum = ((timesRolled % 100) + 2) * 3; timesRolled += 3; return(rollSum); } while (!(game = game.Player1Rolls(NextRoll())).IsComplete(1000) && !(game = game.Player2Rolls(NextRoll())).IsComplete(1000)) { } long result = timesRolled * Math.Min(game.P1Score, game.P2Score); Assert.Equal(897798, result); }