Esempio n. 1
0
        public void Solve()
        {
            var length     = this.inputs.Length;
            var kAndlPairs = new List <int>(GetTriangleNumber(this.inputs.Length));

            for (int i = 0; i < length; i++)
            {
                for (int j = i + 1; j < length; j++)
                {
                    kAndlPairs.Add(this.inputs[i] + this.inputs[j]);
                }
            }

            var store = new IntBucketSet(kAndlPairs);

            for (int i = 0; i < length; i++)
            {
                for (int j = i + 1; j < length; j++)
                {
                    var requiredValue = this.target - (this.inputs[i] + this.inputs[j]);
                    if (!store.Contains(requiredValue))
                    {
                        continue;
                    }

                    Log.Information("Match: {A} * {B} * {C} = {D}", this.inputs[i], this.inputs[j], requiredValue, this.inputs[i] * this.inputs[j] * requiredValue);
                    return;
                }
            }
        }
        public void Solve()
        {
            Array.Sort(this.inputs);

            var length = this.inputs.Length;
            var store  = new IntBucketSet(this.inputs);

            for (int i = length - 1; i >= 0; i--)
            {
                var iValue = this.inputs[i];
                for (int j = length - 1; j >= i + 1; j--)
                {
                    var jValue        = this.inputs[j];
                    var requiredValue = this.target - (iValue + jValue);
                    if (!store.Contains(requiredValue))
                    {
                        continue;
                    }

                    Log.Information("Match: {A} * {B} * {C} = {D}", iValue, jValue, requiredValue, iValue * jValue * requiredValue);
                    return;
                }
            }
        }