diff --git a/frog-2.py b/frog-2.py index c0b0eec..831451b 100644 --- a/frog-2.py +++ b/frog-2.py @@ -1,38 +1,38 @@ -def frog(final_dist=100,max=6): +#import matplotlib +#import matplotlib.pyplot as plt +import math +import random + +count = 0 +hops = 0 +average = 0 +remaining = 0 +results = [] +plot = [] +#pad counts to test for +values = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500] +for i in values: + remaining = i + #run each value 5000 times + while count <= 5000: + if remaining > 0: + remaining -= random.randint(1,remaining) + hops +=1 + if remaining == 0: + results.append(hops) + average = sum(results) / len(results) + count += 1 + hops = 0 + remaining = i + results = [] - # I wrote this quickly in a pub - # Don't judge me - - total_dist = 1 - - while total_dist <= final_dist: - - import random - - cap = 10**max - - trials = 0 - total_leaps = 0 - - while trials <= cap: - - dist = total_dist - leaps = 0 - - while dist > 0: - this_jump = int(random.random()*(dist)+1) - dist -= this_jump - leaps += 1 - - total_leaps += leaps - - trials += 1 - - print "{0}\t{1}".format(total_dist,(total_leaps*1.0)/trials) - - total_dist += 1 - - return "DONE" - - - \ No newline at end of file + #print("values = ", i, " count =", count-1, " average =", average) + #print("{:.2f}".format(average)) + plot.append("{:.2f}".format(average)) + count = 0 + print("Pad Count: ", i, "\tAverage: ", "{:.2f}".format(average)) +#cannot get matplotlib to work correctly with floats. discarding for now. +#plt.plot(values,plot) +#plt.show() +#plt.savefig('test.png') +