Created
October 17, 2013 20:25
-
-
Save ylegall/7031638 to your computer and use it in GitHub Desktop.
combinations
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
import std.stdio; | |
import std.algorithm; | |
void combinations(T)(T[] array) { | |
comb(array, []); | |
} | |
private void comb(T)(T[] array, T[] prefix) { | |
if (array.length) { | |
writeln(prefix ~ [array[0]]); | |
comb(array[1..$], prefix ~ [array[0]]); | |
comb(array[1..$], prefix); | |
} | |
} | |
void main() { | |
combinations([1,2,3,4]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment