From e62d6b5a7c98531a9a6b0a4d9ac9045cc0a9bc9a Mon Sep 17 00:00:00 2001 From: pyzro Date: Wed, 18 Sep 2019 12:02:27 -0400 Subject: [PATCH 1/2] Update frog-2.py --- frog-2.py | 76 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/frog-2.py b/frog-2.py index c0b0eec..c3e1d7e 100644 --- a/frog-2.py +++ b/frog-2.py @@ -1,38 +1,40 @@ -def frog(final_dist=100,max=6): +import matplotlib +matplotlib.use('agg') +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)) + +plt.plot(values,plot) +plt.ylim([0, round(float(max(plot)))+1]) +plt.show() +plt.savefig('test.png') + From aab3333f535cf98aa8289fecc3b1cc78aff32dd1 Mon Sep 17 00:00:00 2001 From: pyzro Date: Wed, 18 Sep 2019 13:55:56 -0400 Subject: [PATCH 2/2] remove maplotlib --- frog-2.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/frog-2.py b/frog-2.py index c3e1d7e..831451b 100644 --- a/frog-2.py +++ b/frog-2.py @@ -1,6 +1,5 @@ -import matplotlib -matplotlib.use('agg') -import matplotlib.pyplot as plt +#import matplotlib +#import matplotlib.pyplot as plt import math import random @@ -32,9 +31,8 @@ plot.append("{:.2f}".format(average)) count = 0 print("Pad Count: ", i, "\tAverage: ", "{:.2f}".format(average)) - -plt.plot(values,plot) -plt.ylim([0, round(float(max(plot)))+1]) -plt.show() -plt.savefig('test.png') +#cannot get matplotlib to work correctly with floats. discarding for now. +#plt.plot(values,plot) +#plt.show() +#plt.savefig('test.png')