Beispiel #1
0
        private static void Part2(string value)
        {
            /*
             * Now, the jumps are even stranger: after each jump, if the offset
             * was three or more, instead decrease it by 1. Otherwise, increase
             * it by 1 as before.
             *
             * Using this rule with the above example, the process now takes
             * 10 steps, and the offset values after finding the exit are
             * left as 2 3 2 3 -1.
             *
             * How many steps does it now take to reach the exit?
             */
            var args = new TraverseArgs()
            {
                Max = 3
            };

            var output = new NullOutput();

            Test.Verify <string, TraverseArgs, int>(output, Traverse, Input.Part2TestInput, args, Input.Part2Test1Answer);
            var result = Traverse(Input.Value, args);

            Write.ColorLine($"Result: {result}", ConsoleColor.Cyan);
            Console.WriteLine();
        }
Beispiel #2
0
        static void Part2(string input)
        {
            /*
             * Now, instead of considering the next digit, it wants you to consider the digit halfway
             * around the circular list. That is, if your list contains 10 items, only include a digit
             * in your sum if the digit 10/2 = 5 steps forward matches it.
             * Fortunately, your list has an even number of elements.
             *
             * For example:
             *
             * - 1212 produces 6: the list contains 4 items, and all four digits match the digit 2 items ahead.
             * - 1221 produces 0, because every comparison is between a 1 and a 2.
             * - 123425 produces 4, because both 2s match each other, but no other digit has a match.
             * - 123123 produces 12.
             * - 12131415 produces 4.
             */
            Write.ColorLine("Part 2", ConsoleColor.Yellow);
            var output = new NullOutput();

            Test.Verify <string, int>(output, SolvePart2, "1212", 6);
            Test.Verify <string, int>(output, SolvePart2, "1221", 0);
            Test.Verify <string, int>(output, SolvePart2, "123425", 4);
            Test.Verify <string, int>(output, SolvePart2, "123123", 12);
            Test.Verify <string, int>(output, SolvePart2, "12131415", 4);

            var answer = SolvePart2(input);

            Write.ColorLine($"Solution: {answer}", ConsoleColor.Cyan);
        }
Beispiel #3
0
        public void Output_Of_String()
        {
            var so = new NullOutput();

            Assert.DoesNotThrow(() => so.Write("text", null));
            Assert.That(so.ToString(), Is.Empty);
        }
Beispiel #4
0
        public void Output_Of_ValueStringBuilder()
        {
            using var sb = SmartFormat.Utilities.ZStringBuilderExtensions.CreateZStringBuilder();
            sb.Append("text");
            var so = new NullOutput();

            Assert.DoesNotThrow(() => so.Write(sb, null));
        }
Beispiel #5
0
        private NullOutput FillLSENullOutput(TypeMapping typeMapping)
        {
            Dictionary <string, FieldMapping> fieldLookup = typeMapping.FieldMappings.ToDictionary(mapping => mapping.Field.Identifier);
            NullOutput obj = new NullOutput();



            return(obj);
        }
Beispiel #6
0
        public IEnumerable <IMeasurement> Unmap(NullOutput outputData, _NullOutputMeta outputMeta)
        {
            List <IMeasurement> measurements  = new List <IMeasurement>();
            TypeMapping         outputMapping = MappingCompiler.GetTypeMapping(OutputMapping);

            Reset();
            CollectFromLSENullOutput(measurements, outputMapping, outputData, outputMeta);

            return(measurements);
        }
Beispiel #7
0
        private static void Part1()
        {
            /*
             * The message includes a list of the offsets for each jump. Jumps are
             * relative: -1 moves to the previous instruction, and 2 skips the next
             * one. Start at the first instruction in the list. The goal is to
             * follow the jumps until one leads outside the list.
             *
             * In addition, these instructions are a little strange; after each jump,
             * the offset of that instruction increases by 1. So, if you come across
             * an offset of 3, you would move three instructions forward, but change
             * it to a 4 for the next time it is encountered.
             *
             * For example, consider the following list of jump offsets:
             *      0
             *      3
             *      0
             *      1
             *      -3
             *
             * Positive jumps ("forward") move downward; negative jumps move upward.
             * For legibility in this example, these offset values will be written all
             * on one line, with the current instruction marked in parentheses. The
             * following steps would be taken before an exit is found:
             *
             *      (0)  3   0   1   -3  - before we have taken any steps.
             *
             *      (1)  3   0   1   -3  - jump with offset 0 (that is, don't jump at all).
             *                             Fortunately, the instruction is then incremented
             *                             to 1.
             *
             *      2   (3)  0   1   -3  - step forward because of the instruction we just
             *                             modified. The first instruction is incremented
             *                                                 again, now to 2.
             *
             *      2    4   0   1  (-3) - jump all the way to the end; leave a 4 behind.
             *
             *      2   (4)  0   1   -2  - go back to where we just were; increment -3 to -2.
             *
             *      2    5   0   1   -2  - jump 4 steps forward, escaping the maze.
             *
             * In this example, the exit is reached in 5 steps.
             *
             * How many steps does it take to reach the exit?
             */

            var args   = new TraverseArgs();
            var output = new NullOutput();

            Test.Verify <string, TraverseArgs, int>(output, Traverse, Input.Part1Test1Input, args, Input.Part1Test1Answer);
            var result = Traverse(Input.Value, args);

            Write.ColorLine($"Result: {result}", ConsoleColor.Cyan);
            Console.WriteLine();
        }
Beispiel #8
0
        static void Part1(string input)
        {
            Write.ColorLine("Part 1", ConsoleColor.Yellow);

            var output = new NullOutput();

            Test.Verify(output, SolveCaptcha, "1122", 3);
            Test.Verify(output, SolveCaptcha, "1111", 4);
            Test.Verify(output, SolveCaptcha, "1234", 0);
            Test.Verify(output, SolveCaptcha, "91212129", 9);
            Console.WriteLine();

            var answer = SolveCaptcha(input);

            Write.ColorLine($"Solution: {answer}", ConsoleColor.Cyan);
        }
Beispiel #9
0
        private static void Part1(string input)
        {
            /*
             * Each square on the grid is allocated in a spiral pattern starting at a location
             * marked 1 and then counting up while spiraling outward. For example, the first
             * few squares are allocated like this:
             *
             * 17  16  15  14  13
             * 18   5   4   3  12
             * 19   6   1   2  11
             * 20   7   8   9  10
             * 21  22  23---> ...
             * While this is very space-efficient (no squares are skipped), requested data
             * must be carried back to square 1 (the location of the only access port for this
             * memory system) by programs that can only move up, down, left, or right. They
             * always take the shortest path: the Manhattan Distance between the location of
             * the data and square 1.
             *
             * For example:
             *
             * Data from square 1 is carried 0 steps, since it's at the access port.
             * Data from square 12 is carried 3 steps, such as: down, left, left.
             * Data from square 23 is carried only 2 steps: up twice.
             * Data from square 1024 must be carried 31 steps.
             *
             * How many steps are required to carry the data from the square identified in
             * your puzzle input all the way to the access port?
             */
            var output = new NullOutput();

            Test.Verify <string, int>(output, Part1Calc, "1", 0);
            Test.Verify <string, int>(output, Part1Calc, "12", 3);
            Test.Verify <string, int>(output, Part1Calc, "23", 2);
            Test.Verify <string, int>(output, Part1Calc, "1024", 31);
            var answer = Part1Calc(Input);

            Console.WriteLine(answer);
        }
Beispiel #10
0
        //static async Task Main(string[] args) {
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.Error.WriteLine("Specify the moddl file to play.");
                Environment.Exit(1);
                return;
            }

            var moddlPath = args[0];
            var moddl     = File.ReadAllText(moddlPath);

#if true
            using (var output = new AudioOutput <float>()) {
                //await new Player().Play(moddl, output);
                new Player().Play(moddl, output);
                //Console.WriteLine("Press any key to terminate.");
                //Console.ReadKey();
                while (true)
                {
                    Application.DoEvents();
                    Thread.Sleep(10);
                }
            }
            //new Player().Play(moddl, new ConsoleOutput<float>());
#else
            var timeSecs  = 30;
            var output    = new NullOutput <float>(timeSecs * 44100);
            var startTime = DateTime.Now;
            new Player().Play(moddl, output);
            var elapsedTime = DateTime.Now - startTime;
            Console.WriteLine(elapsedTime);
            Console.WriteLine(string.Format("Generation efficency: {0}", timeSecs / elapsedTime.TotalSeconds));
            Console.ReadKey();
#endif
        }
Beispiel #11
0
        public void Output_Of_Span()
        {
            var so = new NullOutput();

            Assert.DoesNotThrow(() => so.Write("text".AsSpan(), null));
        }
Beispiel #12
0
        private void CollectFromLSENullOutput(List <IMeasurement> measurements, TypeMapping typeMapping, NullOutput data, _NullOutputMeta meta)
        {
            Dictionary <string, FieldMapping> fieldLookup = typeMapping.FieldMappings.ToDictionary(mapping => mapping.Field.Identifier);

            {
                // Convert value from "Value" field to measurement
                FieldMapping fieldMapping = fieldLookup["Value"];
                IMeasurement measurement  = MakeMeasurement(meta.Value, Convert.ToDouble(data.Value));
                measurements.Add(measurement);
            }
        }
Beispiel #13
0
        //public static readonly Null Constant = new Null();

//        public override void Instantiate(params dynamic[] input)
//        {
//            Value = new NullOutput(this);
//        }

        public void Setup()
        {
            Value = new NullOutput(this);
        }