fork(2) download
  1. from random import randint
  2.  
  3. money = int(input())
  4. iteration = 0
  5. bet = 1;
  6.  
  7. while money>0 and iteration <= 100000 :
  8. x = randint(-1, 36)
  9. iteration = iteration + 1
  10. if x<=0 or (x%2==0) :
  11. money = money - bet
  12. bet = min(bet*2, money)
  13. else :
  14. money = money + bet
  15. bet = 1
  16. if iteration%100==0 :
  17. print(iteration, money)
  18.  
  19. if money==0 :
  20. print("Bankrupt after %d iterations." %(iteration) )
  21. else :
  22. print("Success after %d iterations with result: %d" %(iteration, money) )
  23.  
Success #stdin #stdout 0.06s 12360KB
stdin
100000
stdout
100 100045
200 100088
300 100125
400 100172
500 100218
600 100264
700 100314
800 100359
900 100424
1000 100472
1100 100524
1200 100575
1300 100623
1400 100677
1500 100716
1600 100767
1700 100816
1800 100867
1900 100917
2000 100968
2100 101011
2200 101055
2300 101100
2400 101140
2500 101181
2600 101236
2700 101293
2800 101342
2900 101393
3000 101445
3100 101495
3200 101544
3300 101592
3400 101638
3500 101684
3600 101735
3700 101790
3800 101840
3900 101892
4000 101903
4100 101965
4200 102015
4300 102061
4400 102110
4500 102157
4600 102205
4700 102249
4800 102301
4900 102341
5000 102391
5100 102435
5200 102480
5300 102529
5400 102581
5500 102622
5600 102674
5700 102685
5800 102766
5900 102813
6000 102855
6100 102908
6200 102955
6300 103008
6400 103061
6500 103108
6600 103159
6700 103205
6800 103248
6900 103298
7000 103344
7100 103383
7200 103423
7300 103477
7400 103513
7500 103560
7600 103616
7700 103661
7800 103711
7900 103720
8000 103800
Bankrupt after 8018 iterations.