Skip to content

Instantly share code, notes, and snippets.

@chipbell4
Created November 8, 2015 02:51
Show Gist options
  • Save chipbell4/f9e3fe35d22e244f45b1 to your computer and use it in GitHub Desktop.
Save chipbell4/f9e3fe35d22e244f45b1 to your computer and use it in GitHub Desktop.
Problem 3 "Planet Mining" Solution
from random import uniform
numberOfCases = 1000
print(numberOfCases + 1)
# an edge case to test for
print('0.1 0.1 1 1')
for i in range(numberOfCases):
starting_concentration = uniform(0.25, 0.5)
ending_concentration = uniform(0.001, 0.01)
volume = uniform(1, 10)
outflow_rate = uniform(1, 10)
print('{0:0.3f} {1:0.3f} {2:0.3f} {3:0.3f}'.format(starting_concentration, ending_concentration, volume, outflow_rate))
from math import log
N = int(input().strip())
for i in range(N):
starting_concentration, ending_concentration, volume, outflow_rate = map(float, input().strip().split())
# the formula for model concentration is exponential, and can be written like this:
# concentration(t) = concentration(0) * exp(-outflow_rate * t / volume)
# If we know concentration(t) = ending_concentration, we can solve for t. This is the formula you get
ending_time = volume / outflow_rate * log(starting_concentration / ending_concentration)
# now pretty print
print('{0:0.3f}h'.format(ending_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment