Last active
December 13, 2015 22:08
-
-
Save aeg/4982271 to your computer and use it in GitHub Desktop.
List要素から順列組合せを得る
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
// Case #1 | |
// リスト要素の順列組合せを得る | |
def list1 = ['a', 'b', 'c'] | |
def list2 = list1.permutations() | |
// Collections.permutations() の結果は HashSet になるので、比較のために ArrayListに変換している | |
assert list2 as ArrayList == [['c', 'b', 'a'], ['a', 'c', 'b'], ['c', 'a', 'b'], | |
['b', 'c', 'a'], ['b', 'a', 'c'], ['a', 'b', 'c']] | |
// Case #2 | |
// リスト要素とリスト要素の組合せを得る | |
def list3 = ['a', 'b'] | |
def list4 = [1, 2] | |
def list5 = [list3, list4].combinations() | |
assert list5 == [['a', 1], ['b', 1], ['a', 2], ['b', 2]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment