Viewing a single comment thread. View all comments

Pitiful_Paramedic895 t1_irxmnrj wrote

15

nautilus_red OP t1_irxy8fh wrote

I am not sure if there is any good way to do that other than paste it in here but here you go.

​

FYI: I first had some serious ugly for loops to simulate it which was extremely slow so I coded it more efficiently as you can find below (probably it's a bit less intuitive though, I don't know).

######### Simulation #########

import random

import numpy as np

k = 50000000

returns = [-5 for i in range(0,36)]+[170]

return_arr = np.array(random.choices(returns, k = k)).reshape(int(k/5000),5000)

return_arr_sum = np.sum(return_arr, axis=1)

return_arr_cumsum = np.cumsum(return_arr,axis=1)

return_arr_aux = np.ones((10000,5000), dtype=int)*10000

return_path = return_arr_cumsum + return_arr_aux

​

######### Chart #########

​

import matplotlib.pyplot as plt

from matplotlib.pyplot import figure

figure(figsize=(15, 7), dpi=100)

# plot 1

plt.subplot(1, 2, 1)

plt.plot(return_path.T, linewidth = 0.2)

plt.title("Roulette Simulation of " + str(5000) + " Bets \n Start = 10'000 \$, 5 $ per Bet \n ("+str(int(k/5000))+" Player Paths Simulated)")

plt.xlabel("# Bets", fontsize=12)

plt.ylabel("Total Money Left", fontsize=12)

# plot 2

plt.subplot(1, 2, 2)

pos = [i for i in [return_path[i][-1]-10000 for i in range(0,len(return_path))] if i>=0]

neg = [i for i in [return_path[i][-1]-10000 for i in range(0,len(return_path))] if i<0]

plt.hist(pos, bins = 100, orientation="horizontal", color="green")

plt.hist( neg, bins = 100, orientation="horizontal", color= "red")

plt.title("Distribution of Player Returns After " + str(5000)+ " Bets")

plt.xlabel("# People", fontsize=12)

plt.ylabel("\n Player Profit/Loss", fontsize=12)

plt.show()

19

xElMerYx t1_iry1935 wrote

You can embed blocks of code like this

'''This code will print a lost containing numbers 1 through 10'''

import numpy as np

np_array = np.array([]) 

for i in range(1, 11) : 
    np_array = np.append(np_array, i) 

print(np_array)

&#x200B;

by using the option found here

20

UwRandom t1_is0xncj wrote

The better way to do this would be to either create a GitHub repo, or a GitHub gist. Repos are harder to work with but have lots of features for collaboration and bug tracking, gists are easy to use and only have a few features, it's meant to share code snippets and that's it.

6

nautilus_red OP t1_is0zotd wrote

I never really used GitHub but it seems that it would be a good investment to look at it if I want to do some more mini projects. Thanks!

2

UwRandom t1_is10p7y wrote

Definitely! It's what most software folks use as a portfolio so I'd highly recommend digging into it at some point :)

2