-
Notifications
You must be signed in to change notification settings - Fork 0
/
card_sorting.py
67 lines (44 loc) · 1.19 KB
/
card_sorting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""PoC prerequisite sorting."""
import beyondki.sorting
def dense_prereqs(cid):
# Create a maximally dense requirement_graph by
# making each card depend on all other
# cards that have a lower cid.
return list(range(1, cid))
def sparse_prereqs(cid):
# Create a sparse prerequisite graph.
if cid <= 60:
return []
return [cid - 30, cid - 60]
def single_prereqs(cid):
# Create a sparse prerequisite graph.
if cid == 1:
return []
return [cid - 1]
def no_prereqs(cid):
return []
def prereq_loop(cid):
if cid == 1:
return [2]
elif cid == 2:
return [1]
else:
return []
def cid_order(cid):
return -cid
def reverse_cid_order(cid):
return -cid
def main() -> None:
"""Run the program."""
import sys
# sys.setrecursionlimit(1000)
# Works OK up to 1500 with 'dense_prereqs' and up to >1200
# with 'sparse_prereqs' and up to 100_000 with no_prereqs.
n_cards = 3
cids = list(range(1, n_cards+1))
sorter = beyondki.sorting.CardSorter(cids, prereq_loop, cid_order)
card_queue = sorter.sort_graphs()
print()
print(card_queue)
if __name__ == '__main__':
main()