Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var      input = System.IO.File.ReadAllText("Inputs/day-13.txt");
            Firewall f     = FirewallFactory.CreateFromString(input);
            Packet   p     = new Packet();

            // Part one
            Console.WriteLine(p.GetTravelCost(f));

            // Part two
            Console.WriteLine(p.GetDelayForNoAlarms(f));
        }
        public void CalculateDelayForNoAlarms()
        {
            var input = @"0: 3
            1: 2
            4: 4
            6: 4";

            Firewall f = FirewallFactory.CreateFromString(input);
            Packet   p = new Packet();

            Assert.Equal(10, p.GetDelayForNoAlarms(f));
        }
        public void CalculateCostOfTraveling()
        {
            var input = @"0: 3
            1: 2
            4: 4
            6: 4";

            Firewall f = FirewallFactory.CreateFromString(input);
            Packet   p = new Packet();

            Assert.Equal(24, p.GetTravelCost(f));
        }
Ejemplo n.º 4
0
        public void CreateFirewallsFromStrings()
        {
            var input = @"0: 3
            1: 2
            4: 4
            6: 4";

            Firewall f = FirewallFactory.CreateFromString(input);

            Assert.Equal(7, f.Depth());
            Assert.Equal(3, f.RangeAtDepth(0));
            Assert.Equal(2, f.RangeAtDepth(1));
            Assert.Equal(1, f.RangeAtDepth(2));
            Assert.Equal(1, f.RangeAtDepth(3));
            Assert.Equal(4, f.RangeAtDepth(4));
            Assert.Equal(1, f.RangeAtDepth(5));
            Assert.Equal(4, f.RangeAtDepth(6));
        }
        public void HandleTicksAndAlarms()
        {
            var input = @"0: 3
            1: 2
            4: 4";

            Firewall f = FirewallFactory.CreateFromString(input);

            // At time 0...
            Assert.True(f.AlarmWillBeTriggered(0, 0));
            Assert.True(f.AlarmWillBeTriggered(1, 0));
            Assert.False(f.AlarmWillBeTriggered(2, 0));
            Assert.False(f.AlarmWillBeTriggered(3, 0));
            Assert.True(f.AlarmWillBeTriggered(4, 0));

            // At time 2...
            Assert.False(f.AlarmWillBeTriggered(0, 2));
            Assert.True(f.AlarmWillBeTriggered(1, 2));
            Assert.False(f.AlarmWillBeTriggered(2, 2));
            Assert.False(f.AlarmWillBeTriggered(3, 2));
            Assert.False(f.AlarmWillBeTriggered(4, 2));
        }