Ejemplo n.º 1
0
        public override void ExecuteTask()
        {
            // solution. we know that 2 ^ 10 == (2 ^ 5) * (2 ^ 5)
            // To get around the .net framework rounding of results for high precision numbers
            // we're chopping the data into manageable chunks and use the lattice multiply method to get exact data.
            int maxParts = (int) (Math.Ceiling((double)power / (double)powerSize));

            var currentProduct = new LatticeMultiplyOperand(new List<int>(){ 1 });
            for(int i = 1; i <= maxParts; i++)
            {
                int multiplierPower = ((i * powerSize) > power) ? power : (i * powerSize);
                int intermediatePower = multiplierPower - ((i - 1) * powerSize);
                // currentProduct = new LatticeMultiplier(currentProduct, (long)Math.Pow(2, intermediatePower)).GetProduct();
                currentProduct = (currentProduct * ((long)Math.Pow(2, intermediatePower)));
            }

            this.Result = currentProduct.Value.Aggregate(0L, (seed, resultData) => seed + resultData).ToString();
        }
Ejemplo n.º 2
0
        public static IEnumerable<int> NumberRaisedToPower(int number, int power)
        {
            // int powerSize = power < 3 ? power : 3;
            int powerSize = GetBestPowerChunk(number, power);

            int maxParts = (int)(Math.Ceiling((double)power / (double)powerSize));

            LatticeMultiplyOperand currentProduct = new LatticeMultiplyOperand(new List<int>() { 1 });
            for (int i = 1; i <= maxParts; i++)
            {
                int multiplierPower = ((i * powerSize) > power) ? power : (i * powerSize);
                int intermediatePower = multiplierPower - ((i - 1) * powerSize);
                //currentProduct = new LatticeMultiplier(currentProduct, (long)Math.Pow(number, intermediatePower)).GetProduct();
                //currentProduct = new LatticeMultiplier(currentProduct, GetNumberArray((long)Math.Pow(number,intermediatePower))).GetProduct();

                currentProduct = (currentProduct * (long)Math.Pow(number, intermediatePower));
            }

            return currentProduct.Value;
        }