Ejemplo n.º 1
0
        public int Part1(string input)
        {
            input += '-';

            var count = 0;

            for (var i = 0; i < 128; ++i)
            {
                var inVal = input + i.ToString();
                var hash  = _Day10.Part2(inVal);

                for (var pos = 0; pos < hash.Length; pos += 8)
                {
                    var part      = hash.Substring(pos, 8);
                    var partAsInt = int.Parse(part, System.Globalization.NumberStyles.HexNumber);
                    count += NumberOfSetBits(partAsInt);
                }
            }
            return(count);
        }
Ejemplo n.º 2
0
        public int Part1(string input)
        {
            int ret        = 0;
            var knotHasher = new Day10();

            for (int r = 0; r < 128; r++)
            {
                var hash      = knotHasher.Part2($"{input}-{r}");
                var binString = string.Join(string.Empty, hash.Select(c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')).ToArray());
                for (int c = 0; c < binString.Length; c++)
                {
                    var asInt = int.Parse(binString[c].ToString());
                    arr[r, c] = asInt;
                    ret      += asInt;
                }
            }

            return(ret);
        }