Example #1
0
        public static Wire ParseWire(Circut circut, string line)
        {
            var match       = _wireConnectionRE.Match(line);
            var wireName    = match.Groups["wire"].Value;
            var rawProvider = match.Groups["provider"].Value;

            return(new Wire(circut, wireName, rawProvider));
        }
Example #2
0
        private static SignalProvider ParseSingleProvider(string rawProvider, Circut circut)
        {
            ushort value = 0;

            if (ushort.TryParse(rawProvider, out value))
            {
                return(new SignalProvider(value));
            }

            return(circut.AllWires[rawProvider]);
        }
Example #3
0
        public object SolvePartOne()
        {
            var circut = new Circut();
            var lines  = InputLineParser.GetAllLines(Day07Input.BOOKLET);

            foreach (var line in lines)
            {
                var wire = WireParser.ParseWire(circut, line);
                circut.AllWires.Add(wire.ID, wire);
            }

            var wireA = circut.AllWires["a"];

            return(wireA.GetValue());
        }
Example #4
0
        public object SolvePartTwo()
        {
            var circut       = new Circut();
            var inputPartOne = Day07Input.BOOKLET;
            var inputPartTwo = inputPartOne.Replace("1674 -> b", "46065 -> b");
            var lines        = InputLineParser.GetAllLines(inputPartTwo);

            foreach (var line in lines)
            {
                var wire = WireParser.ParseWire(circut, line);
                circut.AllWires.Add(wire.ID, wire);
            }

            var wireA = circut.AllWires["a"];

            return(wireA.GetValue());
        }
Example #5
0
        public static SignalProvider ParseProviderType(string rawProvider, Circut circut)
        {
            Debug.WriteLine(rawProvider);
            var andMatch = AndRe.Match(rawProvider);

            if (andMatch.Success)
            {
                var one = andMatch.Groups["one"].Value;
                var two = andMatch.Groups["two"].Value;

                var wireOne = ParseSingleProvider(one, circut);
                var wireTwo = ParseSingleProvider(two, circut);

                return(new AndGate(wireOne, wireTwo));
            }

            var orMatch = OrRe.Match(rawProvider);

            if (orMatch.Success)
            {
                var one = orMatch.Groups["one"].Value;
                var two = orMatch.Groups["two"].Value;

                var wireOne = ParseSingleProvider(one, circut);
                var wireTwo = ParseSingleProvider(two, circut);

                return(new OrGate(wireOne, wireTwo));
            }

            var notMatch = NotRe.Match(rawProvider);

            if (notMatch.Success)
            {
                var one = notMatch.Groups["one"].Value;

                var wireOne = ParseSingleProvider(one, circut);

                return(new NotGate(wireOne));
            }

            var lshiftMatch = LshiftRe.Match(rawProvider);

            if (lshiftMatch.Success)
            {
                var one   = lshiftMatch.Groups["one"].Value;
                var count = lshiftMatch.Groups["count"].Value;

                var wireOne   = ParseSingleProvider(one, circut);
                var byteCount = byte.Parse(count);

                return(new LshiftGate(wireOne, byteCount));
            }

            var rshiftMatch = RshiftRe.Match(rawProvider);

            if (rshiftMatch.Success)
            {
                var one   = rshiftMatch.Groups["one"].Value;
                var count = rshiftMatch.Groups["count"].Value;

                var wireOne   = ParseSingleProvider(one, circut);
                var byteCount = byte.Parse(count);

                return(new RshiftGate(wireOne, byteCount));
            }

            return(ParseSingleProvider(rawProvider, circut));
        }