Created
September 3, 2019 21:34
-
-
Save vladionescu/0ad5796ccb2138ce44041dc695c07571 to your computer and use it in GitHub Desktop.
Try to solve FLARE ON 2019 #3
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
#!/usr/bin/env python3 | |
class Win(object): | |
ratio_min = 2.0 | |
ratio_max = 2.5 | |
mass = 72 | |
happy = 30 | |
clean = 0 | |
class Try(object): | |
mass = 0 | |
happy = 0 | |
clean_stat = 0 | |
poo = 0.0 | |
activity = "" | |
def print_stats(self): | |
print("Mass:", self.mass) | |
print("Happy:", self.happy) | |
print("Clean:", self.clean_stat) | |
print("Activity:", self.activity) | |
print("Poo:", self.poo) | |
print() | |
print("Ratio:", self.get_ratio()) | |
def get_ratio(self): | |
f = 0 | |
p = 0 | |
for char in self.activity: | |
if char == "p": p += 1 | |
elif char == "f": f += 1 | |
try: | |
return float(f / p) | |
except ZeroDivisionError: | |
return 0.0 | |
def check_win(self): | |
if Win.ratio_min <= self.get_ratio() <= Win.ratio_max: | |
good_ratio = True | |
else: | |
good_ratio = False | |
return (self.mass == Win.mass) and (self.happy == Win.happy) and (self.clean_stat == Win.clean) and (good_ratio) | |
def clean(self): | |
self.activity += "c" | |
if self.poo: self.poo -= 1.0 | |
self.happy -= 1 | |
self.clean_stat += 6 | |
def feed(self): | |
self.activity += "f" | |
self.mass += 10 | |
self.happy += 2 | |
self.clean_stat -= 1 | |
self.poo += 0.34 | |
def play(self): | |
self.activity += "p" | |
self.mass -= 2 | |
self.happy += 4 | |
self.clean_stat -= 1 | |
sol = Try() | |
def Test(): | |
sol.mass = Win.mass | |
sol.happy = Win.happy | |
sol.clean_stat = Win.clean | |
sol.activity = "fffffffppp" | |
try: | |
while True: | |
if sol.check_win(): | |
sol.print_stats() | |
print("Win!") | |
break | |
if sol.mass >= Win.mass: | |
if sol.happy < Win.happy: | |
# Happy too low, must increase | |
sol.play() | |
elif sol.happy > Win.happy: | |
# Happy too high, must decrease | |
sol.clean() | |
else: | |
# Happy | |
pass | |
if sol.clean_stat > Win.clean: | |
# Too clean, must decrease | |
sol.feed() | |
elif sol.clean_stat < Win.clean: | |
sol.clean() | |
elif sol.mass < Win.mass: | |
# Mass too low, increase it | |
# Feed is the only function that increases mass | |
sol.feed() | |
except KeyboardInterrupt: | |
sol.print_stats() |
I solved it by manually doing the math and verifying with the script :|
Solution:
feed x 8
play x 4
clean x 2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running try1.py results in this when ^C after running for a few seconds.