Beispiel #1
0
        public long BrutePart1()
        {
            _lastOutput = 0;

            for (int i = 4; i < 15; i++)
            {
                var bruteforce = Ext.GetCombinations(GenerateCode().ToList(), i);

                Parallel.ForEach(bruteforce, (_input, _state) =>
                {
                    var input = _input.ToList();

                    foreach (var code2 in input.GetPermutations(input.Count))
                    {
                        if (RunSprintBot(code2, "WALK"))
                        {
                            code2.ToList().ForEach(Console.WriteLine);
                            _state.Stop();
                        }
                    }
                });

                if (_lastOutput > 10)
                {
                    return(_lastOutput);
                }
            }

            throw new InvalidProgramException();
        }
Beispiel #2
0
        public override string Part1()
        {
            var moons = GetMoons().ToList();
            var pairs = Ext.GetCombinations(moons, 2).Select(x => (x.First(), x.Last())).ToList();
            var steps = 1000;

            while (steps-- > 0)
            {
                Step(moons, pairs);
            }

            return(moons.Select(x => x.Energy).Sum().ToString());
        }
Beispiel #3
0
        public override string Part2()
        {
            var init   = GetMoons().ToList();
            var moons  = GetMoons().ToList();
            var pairs  = Ext.GetCombinations(moons, 2).Select(x => (x.First(), x.Last())).ToList();
            var cycles = new ulong[3];

            ulong steps = 0;

            while (true)
            {
                steps++;
                Step(moons, pairs);

                for (var j = 0; j < 3; j++)
                {
                    var ok = true;
                    foreach (var i in Enumerable.Range(0, moons.Count))
                    {
                        if (!(moons[i].Pos[j] == init[i].Pos[j] && moons[i].Vel[j] == 0 && cycles[j] == 0))
                        {
                            ok = false;
                            break;
                        }
                    }

                    if (ok)
                    {
                        cycles[j] = steps;
                    }
                }

                if (cycles.All(x => x != 0))
                {
                    return(Ext.NWW(cycles[0], Ext.NWW(cycles[1], cycles[2])).ToString());
                }
            }
        }