Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions frog-2.py
Original file line number Diff line number Diff line change
@@ -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"



#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')