Created
April 10, 2025 03:17
-
-
Save luoxufeiyan/aa025646d0e8b0a12e5f085afc8f22f2 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
# https://v2ex.com/t/1124068 | |
import random | |
# Initialize constants | |
M = 1000 | |
N = 10 | |
MIN_MONEY = 1 | |
MAX_MONEY = int(M * 0.3) | |
lucky_money = [MIN_MONEY for _ in range(N)] | |
remain_money_bank = M - (MIN_MONEY * N) | |
# Create list of candidate indices | |
candidate_lst = list(range(N)) | |
# Distribute remaining money | |
while remain_money_bank > 0: | |
if not candidate_lst: | |
print("No Solution!") | |
break | |
random_index = random.choice(candidate_lst) | |
if lucky_money[random_index] >= MAX_MONEY: | |
candidate_lst.remove(random_index) | |
else: | |
lucky_money[random_index] += 1 | |
remain_money_bank -= 1 | |
print(lucky_money) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment