Created
April 16, 2024 16:00
-
-
Save julian-klode/0bc66cdf8133a1fcb893a85b00bca4c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 math | |
import random | |
mirrors = [f"m{i:02}" for i in range(45)] | |
active_mirrors = {} | |
sent_so_far = 0 | |
for item in (f"i{i:02}" for i in range(90)): | |
if math.floor(math.sqrt(sent_so_far + 1)) > len(active_mirrors): | |
chosen = random.choice(mirrors) | |
print(f"Adding mirror #{len(active_mirrors)+1}: {chosen}") | |
mirrors.remove(chosen) | |
active_mirrors[chosen] = [] | |
least_used_mirror = min(active_mirrors, key=lambda k: len(active_mirrors[k])) | |
active_mirrors[least_used_mirror].append(item) | |
sent_so_far += 1 | |
print(item) | |
for mirror, items in active_mirrors.items(): | |
print(" ", mirror, " ".join(items)) | |
Author
julian-klode
commented
Apr 16, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment