/// <summary> /// Gets the number of squares used for the specified key. /// </summary> /// <param name="key">The key to use to find the number of squares used.</param> /// <returns> /// The number of squares used for the specified key string. /// </returns> public static int GetSquaresUsed(string key) { int squaresUsed = 0; for (int i = 0; i < 128; i++) { string input = $"{key}-{i}"; string knotHash = Day10.ComputeHash(input); int[] numbers = knotHash .Select((p) => Parse <int>(p.ToString(), NumberStyles.HexNumber)) .ToArray(); var bits = numbers .Select((p) => BitConverter.GetBytes(p)) .Select((p) => new BitArray(p)) .ToArray(); squaresUsed += bits .SelectMany((p) => p.OfType <bool>().Take(4)) .Where((p) => p) .Count(); } return(squaresUsed); }
public static void Y2017_Day10_ComputeHash_Returns_Correct_Value(string asciiBytes, string expected) { // Act string actual = Day10.ComputeHash(asciiBytes); // Assert actual.ShouldBe(expected); }