Skip to content

Instantly share code, notes, and snippets.

@edgesider
Last active May 4, 2019 03:53
Show Gist options
  • Save edgesider/befe705f9e84606c1a1cbd1056ddfd18 to your computer and use it in GitHub Desktop.
Save edgesider/befe705f9e84606c1a1cbd1056ddfd18 to your computer and use it in GitHub Desktop.
多显示器排列组合
# 有三个显示器
outs = ['e1', 'h1', 'e2']

# 需要得到的数组
[['e1'],
 ['h1'],
 ['e2'],
 ['e1', 'h1'],
 ['e1', 'e2'],
 ['h1', 'e1'],
 ['h1', 'e2'],
 ['e2', 'e1'],
 ['e2', 'h1'],
 ['e1', 'h1', 'e2'],
 ['e1', 'e2', 'h1'],
 ['h1', 'e1', 'e2'],
 ['h1', 'e2', 'e1'],
 ['e2', 'e1', 'h1'],
 ['e2', 'h1', 'e1']]

## 思路:为每个长度为i的数组中,加入还不存在的元素,得到长度为i+1的数组

choices = []
pre = [[]] # 每个pre中,记录了长度相同的组合
for _ in outs:
    new = []
    for p in pre:
        for o in outs:
            if not o in p:
                # 加入不存在的元素,得到新组合,加入new数组中
                new.append(p + [o])
    pre = new
    choices.extend(new)
print(choices)

最终拼接成类似这样的命令:

xrandr --output e1 --auto --output h1 --auto --right-of e1

xrandr --output e1 --auto --output h1 --auto --same-as e1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment