Created
June 11, 2020 20:10
-
-
Save grishace/5806ef057dbe04b0db11058e87eb51b0 to your computer and use it in GitHub Desktop.
Arithmetic || geometric progression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var arr = new [] { 0, 2, 4, 6, 8, 10 }; | |
Func<int[], bool, Func<int, Tuple<bool, int>, bool>, bool> aggregate = | |
(a, b, fn) => a.Skip(2).Aggregate(Tuple.Create(b, a[1]), (res, i) => Tuple.Create(res.Item1 && fn(i, res), i)).Item1; | |
var diff = arr[1] - arr[0]; | |
var isA = aggregate(arr, true, (i, r) => i - r.Item2 == diff); | |
arr = new [] { 1, 2, 4, 8, 16, 32 }; | |
diff = arr[1] / arr[0]; | |
var isG = aggregate(arr, arr[1] % arr[0] == 0, (i, r) => i / r.Item2 == diff && i % r.Item2 == 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment