Skip to content

Commit d9b5a26

Browse files
author
standupmaths
authored
Add files via upload
This is the code I wrote as mentioned in this video: https://youtu.be/ZLTyX4zL2Fc
0 parents  commit d9b5a26

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

frog-2.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
def frog(final_dist=100,max=6):
2+
3+
# I wrote this quickly in a pub
4+
# Don't judge me
5+
6+
total_dist = 1
7+
8+
while total_dist <= final_dist:
9+
10+
import random
11+
12+
cap = 10**max
13+
14+
trials = 0
15+
total_leaps = 0
16+
17+
while trials <= cap:
18+
19+
dist = total_dist
20+
leaps = 0
21+
22+
while dist > 0:
23+
this_jump = int(random.random()*(dist)+1)
24+
dist -= this_jump
25+
leaps += 1
26+
27+
total_leaps += leaps
28+
29+
trials += 1
30+
31+
print "{0}\t{1}".format(total_dist,(total_leaps*1.0)/trials)
32+
33+
total_dist += 1
34+
35+
return "DONE"
36+
37+
38+

0 commit comments

Comments
 (0)