Esempio n. 1
0
        public object GetResult2()
        {
            long highest = 0;

            for (int n = 0; n < wholeValues.Count; n++)
            {
                var wv1 = wholeValues[n];
                for (int i = 0; i < wholeValues.Count; i++)
                {
                    if (n == i)
                    {
                        continue;
                    }

                    var wv2 = wholeValues[i];
                    var mag = WholeValue.Add(wv1, wv2).Magnitude;

                    if (mag > highest)
                    {
                        highest = mag;
                    }
                }
            }

            return(highest);
        }
Esempio n. 2
0
        public void Testp2Case()
        {
            var fline = "[[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]]";
            var sline = "[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]]";

            var first  = Parser.ParseLine(fline);
            var second = Parser.ParseLine(sline);

            var sum = WholeValue.Add(first, second);

            Assert.AreEqual("[[[[7,8],[6,6]],[[6,0],[7,7]]],[[[7,8],[8,8]],[[7,9],[0,6]]]]", sum.pair.ToString());

            Assert.AreEqual(3993, sum.Magnitude);
        }
Esempio n. 3
0
        public static WholeValue Add(WholeValue left, WholeValue right)
        {
            var pair = new TreeNode(left.pair.Clone(), right.pair.Clone());

            return(new WholeValue(pair, true));
        }
Esempio n. 4
0
 public WholeValue AggregateAdd() => wholeValues.Aggregate((a, b) => WholeValue.Add(a, b));