예제 #1
0
    public static void Part1()
    {
        var values     = InputParser.FileIntArray("D6.txt", "\t");
        var PastValues = new List <int[]>();

        Printer.Print(values);
        int steps = 0;

        while (PastValues.Where(a => a.SequenceEqual(values)).Count() == 0)
        {
            PastValues.Add((int[])values.Clone());

            int maxI = Utils.IndexOfFirstMax(values);
            var bank = values[maxI];
            values[maxI] = 0;
            for (int i = maxI + 1; i < maxI + 1 + bank; i++)
            {
                values[i % values.Length]++;
            }
            Printer.Print(values);
            steps++;
        }

        var index = PastValues.FindIndex(async => async.SequenceEqual(values));

        Console.WriteLine(String.Format("{0} steps with repeated seen after {1} cycles", steps, (PastValues.Count - index)));
    }
예제 #2
0
        public static void Part1()
        {
            var instructions = InputParser.FileIntArray("D5Part1.txt", "\n");

            int i       = 0;
            int nbSteps = 0;

            while (i < instructions.Length)
            {
                nbSteps++;

                var lastStep = i;
                i += instructions[i];

                instructions[lastStep]++;
            }
            Console.WriteLine(nbSteps);
        }