public int DigitSumEqual(int upperLimit, Func <int, int> digitMap) { var digitMapLookup = new KeyValueMap <int, int>(digitMap); Func <IEnumerable <int>, int> digitSum = xs => xs.Select(digitMapLookup.GetValue).Sum(); return(Enumerable.Range(10, upperLimit) .Select(x => new { Num = x, ListNum = BigNumberHelper.GetAsListRepresentingNumber(x) }) .Where(x => x.Num == digitSum(x.ListNum)) .Sum(x => x.Num)); }
public void Problem97() { var q = Enumerable.Repeat(2, 7830457); var rt = q.Aggregate(Enumerable.Repeat <int>(1, 1).ToList(), (x, y) => BigNumberHelper.MultiplyListRepresentingNumber(x, y, 10)); //MultiplyListRepresentingNumberVoid(rt, 28433); var d = BigNumberHelper.GetAsListRepresentingNumber(28433); var s = BigNumberHelper.MultiplyListRepresentingNumber(rt, d); }
public int Problem25() { List <int> result = new List <int>(); List <int> prevprev = BigNumberHelper.GetAsListRepresentingNumber(1); List <int> prev = BigNumberHelper.GetAsListRepresentingNumber(1); int n = 2; while (result.Count() < 1000) { result = BigNumberHelper.AddListRepresentingNumbers(prevprev, prev); prevprev = prev; prev = result; n++; } return(n); }
public int Problem20() { int i = 100; List <int> num = BigNumberHelper.GetAsListRepresentingNumber(i); while (i > 1) { List <int> num2 = BigNumberHelper.GetAsListRepresentingNumber(i - 1); num = BigNumberHelper.MultiplyListRepresentingNumber(num, num2); i--; } int answer = num.Sum(); return(answer); }