Skip to content
Open
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions frog-2.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import random

def frog(final_dist=100,max=6):

# 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
Expand All @@ -33,6 +33,10 @@ def frog(final_dist=100,max=6):
total_dist += 1

return "DONE"


def main():
frog()


if __name__ == '__main__':
main()

30 changes: 30 additions & 0 deletions frog-ph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Paul Holt
# pcholt@gmail.com
# hereby committed to the PUBLIC DOMAIN

def _crossing_hop_count(hops_remaining):
count = 0
while hops_remaining > 0:
hops_remaining -= random.randrange(1,hops_remaining+1)
count += 1
return count

def crossing_histogram(pond_size, samples):
hist = [0 for i in xrange(pond_size+1)]
for i in xrange(samples):
hist[_crossing_hop_count(pond_size)] += 1
return hist

def average(samples=10**5, pond_size=3):
histogram = crossing_histogram(pond_size,samples)
total = 0
for hop_count, occurrences in enumerate(histogram):
total += hop_count * occurrences
return (total/float(samples), histogram)

def main():
for pond_size in xrange(200):
print pond_size, average(pond_size=pond_size)

if __name__ == '__main__':
main()