Exemplo n.º 1
0
        private static int CalculateNumberOfDiceShowingOnes(decimal n2, decimal n1)
        {
            var m = MobiusUtility.MobiusSieve((int)n2);

            for (int i = 0; i < m.Length; i++)
            {
                if (m[i] == -1)
                {
                    m[i] = 0;
                }
            }

            ArrayExtensions.MutableCumulativeSum(m);

            var index      = Enumerable.Range(1, (int)n1).Select(a => n2 / (decimal)Math.Pow(a, 3d / 2));
            var roundIndex = index.Select(x => (int)Math.Round(x, 6));

            var s = 0;

            foreach (var a in roundIndex)
            {
                s += m.ElementAt(a);
            }

            return(s);
        }
Exemplo n.º 2
0
        public void MobiusSieve_SmallNumberOfDice_ReturnsArrayOfValues()
        {
            var result = MobiusUtility.MobiusSieve(75); // 0:75 (\mu(0):=0)
            var value  = new int[]
            {
                0, 1, -1, -1, 0, -1, 1, -1, 0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1, 0, 1, 1, -1, 0, 0, 1, 0, 0, -1, -1,
                -1, 0, 1, 1, 1, 0, -1, 1, 1, 0, -1, -1, -1, 0, 0, 1, -1, 0, 0, 0, 1, 0, -1, 0, 1, 0, 1, 1, -1, 0, -1, 1,
                0, 0, 1, -1, -1, 0, 1, -1, -1, 0, -1, 1, 0
            };

            Assert.AreEqual(value, result);
        }
Exemplo n.º 3
0
        public void MobiusSieve_VeryLargeNumberOfDice_ReturnsLastValueInArray()
        {
            var result = MobiusUtility.MobiusSieve((int)1e9);

            Assert.AreEqual(0, result.Last());
        }