public void TestIsEven()
        {
            var odd      = PrimeFactorization.IsEven(5);
            var even     = PrimeFactorization.IsEven(14);
            var zero     = PrimeFactorization.IsEven(0);
            var negative = PrimeFactorization.IsEven(-2);

            Assert.AreEqual(false, odd);
            Assert.AreEqual(true, even);
            Assert.AreEqual(true, zero);
            Assert.AreEqual(false, negative);
        }
Exemple #2
0
        public static List <long> GetCollatzSequence(long startingValue)
        {
            if (startingValue <= 0)
            {
                throw new ArgumentException("Value must be bigger than 0.");
            }

            var currentValue = startingValue;
            var result       = new List <long> {
                startingValue
            };

            while (currentValue != 1)
            {
                currentValue = PrimeFactorization.IsEven(currentValue) ? ApplyRuleForEvenNumber(currentValue) : ApplyRuleForOddNumber(currentValue);
                result.Add(currentValue);
            }
            return(result);
        }