コード例 #1
0
ファイル: Day13.cs プロジェクト: JDSustar/adventofcode2020
            public long FindSequentialTime()
            {
                long[] n = Busses.Select(b => (long)b.ID).ToArray();
                long[] a = Busses.Select(b => (long)b.ID - (long)b.Position).ToArray();

                long answer = ChineseRemainderTheorem.Solve(n, a);

                return(answer);
            }
コード例 #2
0
        public override long SolvePart2()
        {
            List <int> busIds = new List <int>();
            List <int> a      = new List <int>();

            for (int i = 0; i < this.busIds.Length; i++)
            {
                if (this.busIds[i].Equals("x"))
                {
                    continue;
                }

                int busIdConverted = Convert.ToInt32(this.busIds[i]);
                busIds.Add(busIdConverted);
                a.Add(busIdConverted - i % busIdConverted);
            }

            return(ChineseRemainderTheorem.Solve(busIds.ToArray(), a.ToArray()));
        }