public void Problem42() { var words = FileSequences.Items(@".\Data\Words.txt", new string[] { "\",", "\"" }); int triangle = words.Select(n => n.Select(l => (int)l - 64) .Sum()) .Count(n => ((long)n).IsTriangle()); Assert.AreEqual(162, triangle); }
public void Problem67() { var triangle = FileSequences.Items(@".\Data\Triangle.txt", new string[] { "\r\n" }) .Select(row => row.Split(' ').Select(items => int.Parse(items)).ToArray()) .ToArray(); var maxPath = triangle.CollapseTree(); if (maxPath != 7273) { throw new InvalidOperationException("Problem not solved correctly"); } }
public void Problem22() { int i = 1; int result = FileSequences.Items(@".\Data\Names.txt", new string[] { "\",", "\"" }) .OrderBy(n => n) .Select(n => n.Select(l => (int)l - 64).Sum() * i++) .Sum(); if (result != 871198282) { throw new InvalidOperationException("Problem not solved correctly"); } }
public void Problem54() { var result = FileSequences.Items(@".\Data\Poker.txt", new string[] { "\r\n" }) .Select(game => game.Split(' ')) .Select(cards => Tuple.Create(new PokerHand(cards.Take(5).ToArray()), new PokerHand(cards.Skip(5).Take(5).ToArray()))) .ToList(); int player1Wins = 0; int player2Wins = 0; foreach (var game in result) { var player1Hand = game.Item1.GetBestHand(); var player2Hand = game.Item2.GetBestHand(); if (player1Hand.Item1 > player2Hand.Item1) { player1Wins++; } if (player2Hand.Item1 > player1Hand.Item1) { player2Wins++; } if (player1Hand.Item1 == player2Hand.Item1) { if (player1Hand.Item2.HighCard().Value > player2Hand.Item2.HighCard().Value) { player1Wins++; } if (player2Hand.Item2.HighCard().Value > player1Hand.Item2.HighCard().Value) { player2Wins++; } } } if (player1Wins != 376) { throw new InvalidOperationException("Problem not solved correctly"); } }