Last active
July 5, 2018 02:55
-
-
Save dalinaum/902d22cb4c0fd2b482a6567f60d49212 to your computer and use it in GitHub Desktop.
rotation.py
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
# coding: utf-8 | |
# In[1]: | |
import random | |
import sys | |
# In[2]: | |
scores = { | |
'스팍': 113, | |
'노아': 80, | |
'제롬': 87.5, | |
'마타': 80.5, | |
'케빈': 102, | |
'레니': 61, | |
'아즈키': 74, | |
'지코': 85 | |
} | |
# In[3]: | |
round = 1 | |
min_gap = sys.maxsize | |
opt_team_left = [] | |
opt_team_right = [] | |
opt_sum_left = 0 | |
opt_sum_right = 0 | |
while round <= 5: | |
names = list(scores.keys()) | |
random.shuffle(names) | |
sum_left = 0 | |
sum_right = 0 | |
team_left = [] | |
team_right = [] | |
while names: | |
lhs = names.pop(0) | |
rhs = names.pop(0) | |
score_lhs = scores[lhs] | |
score_rhs = scores[rhs] | |
if (sum_left > sum_right) == (score_lhs > score_rhs): | |
team_left.append(rhs) | |
sum_left += score_rhs | |
team_right.append(lhs) | |
sum_right += score_lhs | |
else: | |
team_left.append(lhs) | |
sum_left += score_lhs | |
team_right.append(rhs) | |
sum_right += score_rhs | |
gap = abs(sum_left - sum_right) | |
print(f"팀 1 {team_left} {sum_left}") | |
print(f"팀 2 {team_right} {sum_right}") | |
print(f"격차: {gap}") | |
if (gap < min_gap): | |
print("팀을 교체합니다.") | |
opt_team_left = team_left | |
opt_team_right = team_right | |
opt_sum_left = sum_left | |
opt_sum_right = sum_right | |
min_gap = gap | |
round += 1 | |
print("=" * 80) | |
print("최종 선출:") | |
print(f"팀 1 {opt_team_left} {opt_sum_left}") | |
print(f"팀 2 {opt_team_right} {opt_sum_right}") | |
print(f"격차: {min_gap}") | |
print("=" * 80) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment