Spaces:
Sleeping
Sleeping
ping98k
commited on
Commit
·
3d7317c
1
Parent(s):
308b8f6
init
Browse files- .idea/.gitignore +8 -0
- .idea/inspectionProfiles/profiles_settings.xml +6 -0
- .idea/llm-brainstorm.iml +10 -0
- .idea/misc.xml +7 -0
- .idea/modules.xml +8 -0
- .idea/vcs.xml +6 -0
- main.py +52 -0
.idea/.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Default ignored files
|
| 2 |
+
/shelf/
|
| 3 |
+
/workspace.xml
|
| 4 |
+
# Editor-based HTTP Client requests
|
| 5 |
+
/httpRequests/
|
| 6 |
+
# Datasource local storage ignored files
|
| 7 |
+
/dataSources/
|
| 8 |
+
/dataSources.local.xml
|
.idea/inspectionProfiles/profiles_settings.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<component name="InspectionProjectProfileManager">
|
| 2 |
+
<settings>
|
| 3 |
+
<option name="USE_PROJECT_PROFILE" value="false" />
|
| 4 |
+
<version value="1.0" />
|
| 5 |
+
</settings>
|
| 6 |
+
</component>
|
.idea/llm-brainstorm.iml
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<module type="PYTHON_MODULE" version="4">
|
| 3 |
+
<component name="NewModuleRootManager">
|
| 4 |
+
<content url="file://$MODULE_DIR$">
|
| 5 |
+
<excludeFolder url="file://$MODULE_DIR$/.venv" />
|
| 6 |
+
</content>
|
| 7 |
+
<orderEntry type="jdk" jdkName="Python 3.13 (llm-brainstorm)" jdkType="Python SDK" />
|
| 8 |
+
<orderEntry type="sourceFolder" forTests="false" />
|
| 9 |
+
</component>
|
| 10 |
+
</module>
|
.idea/misc.xml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="Black">
|
| 4 |
+
<option name="sdkName" value="Python 3.13 (PyCharmMiscProject)" />
|
| 5 |
+
</component>
|
| 6 |
+
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.13 (llm-brainstorm)" project-jdk-type="Python SDK" />
|
| 7 |
+
</project>
|
.idea/modules.xml
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="ProjectModuleManager">
|
| 4 |
+
<modules>
|
| 5 |
+
<module fileurl="file://$PROJECT_DIR$/.idea/llm-brainstorm.iml" filepath="$PROJECT_DIR$/.idea/llm-brainstorm.iml" />
|
| 6 |
+
</modules>
|
| 7 |
+
</component>
|
| 8 |
+
</project>
|
.idea/vcs.xml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0" encoding="UTF-8"?>
|
| 2 |
+
<project version="4">
|
| 3 |
+
<component name="VcsDirectoryMappings">
|
| 4 |
+
<mapping directory="" vcs="Git" />
|
| 5 |
+
</component>
|
| 6 |
+
</project>
|
main.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
|
| 3 |
+
TOP_K = int(os.getenv("TOP_K", 5))
|
| 4 |
+
|
| 5 |
+
def play(a,b):
|
| 6 |
+
return a
|
| 7 |
+
|
| 8 |
+
def tournament(players):
|
| 9 |
+
lost_to = {}
|
| 10 |
+
current = players[:]
|
| 11 |
+
while len(current) > 1:
|
| 12 |
+
next_round = []
|
| 13 |
+
for i in range(0, len(current) - 1, 2):
|
| 14 |
+
a, b = current[i], current[i + 1]
|
| 15 |
+
w = play(a, b)
|
| 16 |
+
loser = b if w == a else a
|
| 17 |
+
lost_to[loser] = w
|
| 18 |
+
next_round.append(w)
|
| 19 |
+
if len(current) % 2 == 1:
|
| 20 |
+
next_round.append(current[-1])
|
| 21 |
+
current = next_round
|
| 22 |
+
champion = current[0]
|
| 23 |
+
return champion, lost_to
|
| 24 |
+
|
| 25 |
+
def get_candidates(champion, lost_to):
|
| 26 |
+
c = {champion}
|
| 27 |
+
for player, opponent in lost_to.items():
|
| 28 |
+
if opponent == champion:
|
| 29 |
+
c.add(player)
|
| 30 |
+
return list(c)
|
| 31 |
+
|
| 32 |
+
def playoff(candidates):
|
| 33 |
+
wins = {p: 0 for p in candidates}
|
| 34 |
+
for i in range(len(candidates)):
|
| 35 |
+
for j in range(i + 1, len(candidates)):
|
| 36 |
+
w = play(candidates[i], candidates[j])
|
| 37 |
+
wins[w] += 1
|
| 38 |
+
return sorted(candidates, key=lambda p: wins[p], reverse=True)
|
| 39 |
+
|
| 40 |
+
def get_top(players, k=TOP_K):
|
| 41 |
+
champion, lost_to = tournament(players)
|
| 42 |
+
runnerup = lost_to.get(champion)
|
| 43 |
+
finalists = [champion] + ([runnerup] if runnerup else [])
|
| 44 |
+
semifinalists = [p for p, o in lost_to.items() if o in finalists and p not in finalists]
|
| 45 |
+
candidates = set(finalists + semifinalists)
|
| 46 |
+
candidates.update(get_candidates(champion, lost_to))
|
| 47 |
+
ranking = playoff(list(candidates))
|
| 48 |
+
return ranking[:k]
|
| 49 |
+
|
| 50 |
+
players = [f"S{i}" for i in range(1, 21)]
|
| 51 |
+
top_picks = get_top(players)
|
| 52 |
+
print(top_picks)
|