立ち位置・仕様
- いろんなアルゴリズムをコピペできるように記録するのみ
- 最適化が目的でない
- たまにメモとして解説を残す
- 最低限でまとめる
- データを抽出しやすいように個別のIDを付与
- あるアルゴリズムにおいて、他のアルゴリズムが登場する際にはそのIDを付与
- IDは16進数表記
- なるべく最低限なパッケージで実装
- なるべく特殊なオブジェクト型は使用しない
TargetID
00.00.00.0a
ReferenceID
円順列の候補
import itertools
def circularPermutation(nodes):
l_list = []
per = []
for l in itertools.permutations(nodes, len(nodes)):
if l not in l_list:
per.append(l)
extend_l = l+l
l_list.extend([extend_l[i:i+len(nodes)] for i in range(len(nodes))])
return per
使用方法
nodes = ['A','B','C','D']
cp = circularPermutation(nodes)
print(cp)
[('A', 'B', 'C', 'D'),
('A', 'B', 'D', 'C'),
('A', 'C', 'B', 'D'),
('A', 'C', 'D', 'B'),
('A', 'D', 'B', 'C'),
('A', 'D', 'C', 'B')]