Last active
April 20, 2020 08:11
-
-
Save z-------------/aa04fc347006193cf3aee5ccf86e1f70 to your computer and use it in GitHub Desktop.
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
| # a - alphabet | |
| # n - sequence length | |
| # | |
| # Example | |
| # | |
| # cartperm([0, 1], 3) | |
| # # => [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1], [1, 1, 0], [1, 1, 1]] | |
| # | |
| def cartperm(a, n) | |
| a.product(* [a] * (n - 1)) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment