import random
oks = [
"A","B","C",
"D","E","F",
"G","H","I",
"J","K","L",
"M","N","O",
"P","Q","R",
"S","T","U",
"V","W","X",
"Y","Z","!",
]
# シャッフル写像
kos = oks[:]
random.shuffle(kos)
# 写像 rt: oks[i] → kos[i]
def rt(lt):
i = oks.index(lt)
return kos[i]
# サイクル検出
def orbit(start):
seen = [] # すでに訪れた要素
x = start
while x not in seen:
seen.append(x)
x = rt(x)
# サイクル開始位置を特定
cycle_start = seen.index(x)
cycle = seen[cycle_start:]
return seen, cycle
# すべての文字について表示
for p in oks:
path, cycle = orbit(p)
print("軌道:", " → ".join(path))
print("周期:", " → ".join(cycle))
print()
To embed this project on your website, copy the following code and paste it into your website's HTML: