Last active
January 5, 2023 15:57
-
-
Save jmccardle/8a98d202cd29d71fff7f61428f4864f7 to your computer and use it in GitHub Desktop.
CasualMath - Weed Infestation
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
rules = {2: 5, 7: 1} | |
weeds = [10] | |
def pick(w, pick, grow): | |
if w == pick: return 0 | |
return w - pick + grow | |
step = 0 | |
while 0 not in weeds: | |
print(f"{step}:{weeds}") | |
new_weeds = [] | |
for r in rules: | |
for w in weeds: | |
if w >= r: | |
value = pick(w, r, rules[r]) | |
#print(f"{w} -> pick {r}, grow {rules[r]} -> {value}") | |
new_weeds.append(value) | |
# convert to set and back to remove duplicates. | |
# if a number of weeds is arrived at by multiple courses of action, then it doesn't need to be considered more than once. | |
weeds = list(set(new_weeds)) | |
step += 1 | |
if step > 10: break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment