public void Part2(string expectedResult, string input) { var codes = input.ToCharArray().Select(c => (int)c); var rejoined = string.Join(",", codes); var saltedInput = rejoined + "," + "17, 31, 73, 47, 23"; var splitCodes = saltedInput.SplitToIntegers(",").ToList(); var knot = new Knot(); for (var i = 0; i < 64; i++) { foreach (var length in splitCodes) { knot.Flip(length); } } var hashSet = new List <int>(); var skip = 0; Func <IList <int> > toHash = () => { var next = knot.List.Skip(skip).Take(16); skip += 16; return(next.ToList()); }; while (skip < knot.MaxSize) { var next = toHash(); var hashPiece = 0; foreach (var piece in next) { hashPiece = hashPiece ^ piece; } hashSet.Add(hashPiece); } var knotHashPieces = hashSet.Select(p => { var piece = p.ToString("X"); if (piece.Length == 1) { piece = "0" + piece; } return(piece); }); var knotHash = string.Join("", knotHashPieces); Assert.AreEqual(expectedResult, knotHash.ToLower()); }
public void Part1(int expectedResult, string input) { var lengths = input.SplitToIntegers(","); var knot = new Knot(); foreach (var length in lengths) { knot.Flip(length); } Assert.AreEqual(expectedResult, knot.MultiplyFirstTwo()); }
public void VerifyKnots(int expectFirst, int expectSecond, int startingLength, string inputLengths) { var lengths = inputLengths.SplitToIntegers(","); var knot = new Knot(startingLength); foreach (var length in lengths) { knot.Flip(length); } Assert.AreEqual(expectFirst, knot.List.First()); Assert.AreEqual(expectSecond, knot.List.Skip(1).First()); }