Beispiel #1
0
        static void Main(string[] args)
        {
            bool confirmed = false;

            do
            {
                Console.WriteLine("Welcome to HackerRank's 30 Days of Code");
                Console.WriteLine("Days");
                for (int i = 0; i < dias.Length; i++)
                {
                    Console.WriteLine(dias[i]);
                }
                Console.WriteLine("Write the day number to be executed: ");
                int opt = Convert.ToInt32(Console.ReadLine());
                switch (opt)
                {
                case 1:
                    Day1.Execute();
                    break;

                case 2:
                    Day2.Execute();
                    break;

                case 3:
                    Day3.Execute();
                    break;

                case 4:
                    Day4.Execute();
                    break;

                case 5:
                    Day5.Execute();
                    break;

                case 6:
                    Day6.Execute();
                    break;

                case 7:
                    Day7.Execute();
                    break;

                case 8:
                    Day8.Execute();
                    break;

                case 9:
                    Day9.Execute();
                    break;

                case 10:
                    Day10.Execute();
                    break;

                case 11:
                    Day11.Execute();
                    break;

                case 12:
                    Day12.Execute();
                    break;

                case 13:
                    Day13.Execute();
                    break;

                case 14:
                    Day14.Execute();
                    break;

                case 15:
                    Day15.Execute();
                    break;

                case 16:
                    Day16.Execute();
                    break;

                case 17:
                    Day17.Execute();
                    break;

                case 18:
                    Day18.Execute();
                    break;

                case 19:
                    Day19.Execute();
                    break;

                case 20:
                    Day20.Execute();
                    break;

                case 21:
                    Day21.Execute();
                    break;

                case 22:
                    Day22.Execute();
                    break;

                case 23:
                    Day23.Execute();
                    break;

                case 24:
                    Day24.Execute();
                    break;

                case 25:
                    Day25.Execute();
                    break;

                case 26:
                    Day26.Execute();
                    break;

                case 27:
                    Day27.Execute();
                    break;

                case 28:
                    Day28.Execute();
                    break;

                case 29:
                    Day29.Execute();
                    break;

                default:
                    Console.WriteLine("Not Implemeted");
                    break;
                }
                ConsoleKey response;
                do
                {
                    Console.Write("Execute another function? (Y/N) ");
                    response = Console.ReadKey(false).Key;
                    if (response != ConsoleKey.Enter)
                    {
                        Console.WriteLine();
                    }
                }while(response != ConsoleKey.Y && response != ConsoleKey.N);
                confirmed = response == ConsoleKey.N;
            }while(!confirmed);
        }
Beispiel #2
0
        public void Part1_RealInput_ProducesCorrectSolution()
        {
            string actual = new Day16().Part1();

            Assert.Equal("bijankplfgmeodhc", actual);
        }
Beispiel #3
0
    public void Day16_Part1(long part1)
    {
        var d = new Day16();

        Assert.Equal(part1.ToString(), d.Part1());
    }
Beispiel #4
0
        public void Part2_RealInput_ProducesCorrectSolution()
        {
            string actual = new Day16().Part2();

            Assert.Equal("bpjahknliomefdgc", actual);
        }
Beispiel #5
0
        public static void GetPhaseEntryTest()
        {
            // Test exampels taken from here:
            // https://adventofcode.com/2019/day/16
            // Input signal: 12345678
            // 1 * 1 + 2 * 0 + 3 * -1 + 4 * 0 + 5 * 1 + 6 * 0 + 7 * -1 + 8 * 0 = 4
            // 1 * 0 + 2 * 1 + 3 * 1 + 4 * 0 + 5 * 0 + 6 * -1 + 7 * -1 + 8 * 0 = 8
            // 1 * 0 + 2 * 0 + 3 * 1 + 4 * 1 + 5 * 1 + 6 * 0 + 7 * 0 + 8 * 0 = 2
            // 1 * 0 + 2 * 0 + 3 * 0 + 4 * 1 + 5 * 1 + 6 * 1 + 7 * 1 + 8 * 0 = 2
            // 1 * 0 + 2 * 0 + 3 * 0 + 4 * 0 + 5 * 1 + 6 * 1 + 7 * 1 + 8 * 1 = 6
            // 1 * 0 + 2 * 0 + 3 * 0 + 4 * 0 + 5 * 0 + 6 * 1 + 7 * 1 + 8 * 1 = 1
            // 1 * 0 + 2 * 0 + 3 * 0 + 4 * 0 + 5 * 0 + 6 * 0 + 7 * 1 + 8 * 1 = 5
            // 1 * 0 + 2 * 0 + 3 * 0 + 4 * 0 + 5 * 0 + 6 * 0 + 7 * 0 + 8 * 1 = 8
            var testData = new List <Tuple <int[], int, int, int> >(new Tuple <int[], int, int, int>[] {
                // Output index: 0
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    0, 0, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    1, 0, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    2, 0, -1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    3, 0, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    4, 0, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    5, 0, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    6, 0, -1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    7, 0, 0),

                // Output index: 1
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    0, 1, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    1, 1, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    2, 1, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    3, 1, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    4, 1, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    5, 1, -1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    6, 1, -1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    7, 1, 0),

                // Output index: 2
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    0, 2, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    1, 2, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    2, 2, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    3, 2, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    4, 2, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    5, 2, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    6, 2, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    7, 2, 0),

                // Output index: 3
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    0, 3, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    1, 3, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    2, 3, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    3, 3, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    4, 3, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    5, 3, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    6, 3, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    7, 3, 0),

                // Output index: 4
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    0, 4, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    1, 4, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    2, 4, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    3, 4, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    4, 4, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    5, 4, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    6, 4, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    7, 4, 1),

                // Output index: 5
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    0, 5, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    1, 5, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    2, 5, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    3, 5, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    4, 5, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    5, 5, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    6, 5, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    7, 5, 1),

                // Output index: 6
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    0, 6, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    1, 6, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    2, 6, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    3, 6, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    4, 6, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    5, 6, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    6, 6, 1),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    7, 6, 1),

                // Output index: 7
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    0, 7, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    1, 7, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    2, 7, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    3, 7, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    4, 7, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    5, 7, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    6, 7, 0),
                new Tuple <int[], int, int, int>(
                    new int[] { 0, 1, 0, -1 },
                    7, 7, 1)
            });

            foreach (var testExample in testData)
            {
                var result = Day16.GetPhaseEntry(
                    basePhasePattern: testExample.Item1,
                    inputIndex: testExample.Item2,
                    outputIndex: testExample.Item3);
                Assert.Equal(testExample.Item4, result);
            }
        }
Beispiel #6
0
 public void Initialize()
 {
     _day16 = new Day16();
 }
Beispiel #7
0
 public void Setup( )
 {
     day16 = new Day16("day16test1");
 }
 public void Setup()
 {
     _day16 = new Day16();
 }