Last active
April 18, 2025 03:29
-
-
Save akku1139/65b928935f072f53fb9ebd704ab06bd5 to your computer and use it in GitHub Desktop.
席替えするプログラム
This file contains 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
import random | |
# 目が悪い人の出席番号 | |
warui = [2, 5, 30] | |
# 出席番号一覧 | |
no = [*range(1, 41)] | |
# 新しい席順 (前半) | |
new = [""]*20 | |
# 目が悪い人を前半に配置する | |
# 前半でランダムにする | |
# 色もつける | |
for i, v in enumerate(warui): | |
new[i] = "\033[46m" + str(v).rjust(2) + "\033[49m" | |
no.remove(v) | |
random.shuffle(new) | |
# 後半のスペースも追加する | |
new.extend([""]*20) | |
# 良いアルゴリズムが思い浮かばなかったので脳筋で突破する | |
for i in range(0, 40): | |
if new[i] == "": | |
n = random.choice(no) | |
new[i] = str(n).rjust(2) | |
no.remove(n) | |
# 机を置かない場所に偽の要素を配置 | |
c = [0, 1, 6, 7, 40, 41, 46, 47] | |
for d in c: | |
new.insert(d, " ") | |
# Geminiに書いてもらった、机8個で1列にする | |
# ついでに1列分を文字列として結合する | |
chunk_size = 8 | |
f = [" ".join(new[i:i + chunk_size]) for i in range(0, len(new), chunk_size)] | |
print("\n".join(f)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment