Skip to content

Instantly share code, notes, and snippets.

@bembengarifin
Created December 28, 2014 16:09
Show Gist options
  • Save bembengarifin/be692a3445463a25dec5 to your computer and use it in GitHub Desktop.
Save bembengarifin/be692a3445463a25dec5 to your computer and use it in GitHub Desktop.
Iterate numbers with recursive
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