Last active
December 17, 2015 03:39
-
-
Save grondilu/5544948 to your computer and use it in GitHub Desktop.
combinations method for Array
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
use MONKEY_TYPING; | |
augment class Array { | |
method combinations(Int $of) { | |
return [] if $of == 0; | |
return () if self.elems == 0; | |
map({ [ self[0], $_[] ] }, [self[1..*-1]].combinations($of-1)), | |
[self[1..*-1]].combinations( $of ); | |
} | |
} | |
my @a = ^5; | |
say .perl for @a.combinations: 2; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment