Created
December 28, 2014 16:09
-
-
Save bembengarifin/be692a3445463a25dec5 to your computer and use it in GitHub Desktop.
Iterate numbers with recursive
This file contains hidden or 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
IEnumerable<int[]> IterateWithReverse(int lower = 0, int upper = 10, int depth = 10, int[] slots = null) | |
{ | |
if (slots == null) slots = new int[depth]; | |
for (int i = lower; i < upper; i++) | |
{ | |
slots[depth - 1] = i; | |
if (depth > 1) | |
foreach (var x in IterateWithReverse(lower, upper, depth - 1, slots)) yield return x; | |
else | |
yield return slots.Reverse().ToArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment