Skip to content

Instantly share code, notes, and snippets.

@equal-l2
Created January 12, 2021 19:20
Show Gist options
  • Save equal-l2/333efe1e721c44bf05ec207c661999b6 to your computer and use it in GitHub Desktop.
Save equal-l2/333efe1e721c44bf05ec207c661999b6 to your computer and use it in GitHub Desktop.
yutanpo
room_temp = 20
hot_temp = 100
def cool(x, time):
assert time >= 0
assert x >= room_temp
# assuming boiling water requires an hour to reach around 40℃
cooling_fact = 4e-4
dt = 0.1
while time > 0:
assert time < 10000
delta = dt * cooling_fact * abs(x - room_temp)
x -= delta
time -= dt
return x
# returns required time to boil x[℃] water
def boil(x):
# assuming boiling water requires 5 minutes
return 3 * (hot_temp - x)
def revolving():
x = room_temp
time_req = 0
while x < 99:
old_x = x
time = boil(x)
if time < 30:
print("tsukareta :( (boiling requires less than a half min)")
break
time_req += time
x = cool(x, time)
new_x = x/2 + hot_temp/2
print(f"{x:.2f}/2 + {hot_temp:.2f}/2 = {new_x:.2f}, total time {int(time_req)} s")
if int(old_x) == int(new_x):
print("on equibilium")
break
x = new_x
def from_scratch():
time = boil(room_temp)
x = cool(hot_temp, boil(room_temp))
new_x = x/2 + hot_temp/2
print(f"{x:.2f}/2 + {hot_temp:.2f}/2 = {new_x:.2f}, total time {2*boil(room_temp)} s")
print(f"room temp: {room_temp}")
print(f"boiling water after a min: {cool(100,60)}")
print(f"boiling water after an hour: {cool(100,3600)}")
print(f"--- revolving ---")
revolving()
print(f"--- from scratch ---")
from_scratch()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment