From b569b0f7c1449126b082320eddc60b450fcd8aac Mon Sep 17 00:00:00 2001 From: Ron Duwell Date: Fri, 29 Nov 2019 10:04:57 -0500 Subject: [PATCH 01/18] bins fixed, should work --- src/main/python/bins.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/python/bins.py b/src/main/python/bins.py index 034e789..7974479 100644 --- a/src/main/python/bins.py +++ b/src/main/python/bins.py @@ -3,8 +3,10 @@ class Bins: def __init__(self, numrolls): self.numberOfRolls = numrolls - bin = {} - for x in range (self.numberOfRolls, self.numberOfRolls * 6): - result ={x:0} - bin.append(result) + def createBin(self): + bin = {} + for x in range (self.numberOfRolls, self.numberOfRolls * 6): + result ={x:0} + bin.append(result) + return bin From fe9ca90c91d8ba440a1f185509ea558aa26a680c Mon Sep 17 00:00:00 2001 From: Ron Duwell Date: Sat, 30 Nov 2019 12:10:41 -0500 Subject: [PATCH 02/18] finished stars, but need to learn how to format and do a main method --- .idea/workspace.xml | 1 - src/main/python/simulation.py | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5a83a5e..e90e99c 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,7 +3,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -329,12 +195,6 @@ - - @@ -356,49 +216,46 @@ + + + + + file://$PROJECT_DIR$/src/main/python/mainapplication.py + 2 + + + file://$PROJECT_DIR$/src/main/python/bins.py + 12 + + + file://$PROJECT_DIR$/src/main/python/bins.py + 13 + + + file://$PROJECT_DIR$/src/main/python/simulation.py + 23 + + + file://$PROJECT_DIR$/src/main/python/simulation.py + 28 + + + file://$PROJECT_DIR$/src/main/python/bins.py + 9 + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/python/__pycache__/bins.cpython-38.pyc b/src/main/python/__pycache__/bins.cpython-38.pyc index 2ec96be776666301ccc92fa1311178a40e5d762f..d87c2d90cca3e3b6b94f1eda6c6cf28bc01a164d 100644 GIT binary patch literal 852 zcmZuv!EO^V5FLAWlO;-MRUrzT5z%Rn}84P+C0gth;?&^D*a z8=*bv3sk#{X33Ty;0(}WN33GWHLu%xR`!*7bJ{C%Rr}+@RuQj#tH!5k6LS>42GhU> zKVQbjRv8RdOn=~QVMaTAcsE*#~JX;P$>8!8q5U8HyNfyzhKps@eq>=YWYluB0wwT<TV2q7=*ryB@uJ$|BCAH MU~}OiRsKMQUkhTfH~;_u delta 405 zcmYjNJx{|x47D#GiYihT)QL(g3}GN68v`(OAyl9)NKutG*U~CY%UwVerD8y0V5>4R z03$zyf54QTp?`pZ2|EmMlArIM{p_dvupg~@$8~E!=jr(~{DNgYz|CdYG|#}Zmk(PZ z*K*9E3o#Iffrq7=UQK#ZoeWN=NuoVbnp!4 zuZVEj$dQa0!OAAZih>@crJ{5w70)j1Xf~5+>=}v|lx8y0S&285$6v6Rulao?qfB;t zqm)N!hXByT2Cj+Q^@CBWcmFy9&nn)<_Az%Vmw}!C1D>gnfJ1Z95spzY^oLdc*IkLN IV&7=|07Md4&j0`b diff --git a/src/main/python/__pycache__/dice.cpython-38.pyc b/src/main/python/__pycache__/dice.cpython-38.pyc index 9d28d6d3f4d4e370e4a74ae7bac07a463c2ff069..4003cde5c1caa543fc25686f60e59ea47ab00b0f 100644 GIT binary patch delta 325 zcmdnRx|EeKl$V!_0SK?m%SDKrYTI8Pw63}G2#ZsJ_lXi<8C<+o-$xy@wH0+nFerR!O zQL%n*W_GH+OKNd;Nq&KTN@|&Ycxr04#bhByBSyB#u8cVXFG0#RS#GfwCFZ547BNpg z$SAJK0u+m4DakJ`zQvdcHV{Iv1I2G~fy5p2Qi4l!IVUqRDKoN8R%KGjD&hc27V&`y zkda6PNLLXPkN_E53?ev~IGDjAnoLDJFj*uWU<1IGaoFVMr!Cg3=F&i zkK&zynT?6#Af$TukI(1-_p#r+4=(5CxH5yE2 zidHQ%r603=S>6}WK-TN$C8ML2zGh7k&FKp`<_Rvsi diff --git a/src/main/python/__pycache__/simulation.cpython-38.pyc b/src/main/python/__pycache__/simulation.cpython-38.pyc index f8543494d075b4ed674f4754402272b7aa60101c..be55d5aeef0306ccdf05d534f65de84a3b6e8628 100644 GIT binary patch literal 1270 zcmZvbPjAyO6u|8`NwcgS2nIvIp@$)nNi-+KA0afxBo3f~C=*ho5oNUp*^;!gQ?ym- zsrwS#y5p{V9A6QKeFaXu=dNq{=2lEZ)$U1bj z27(h#Gm_JYQq--?%2~uHc||zm_6gzk$ck+4v`OHegFgwVwl~s3;eRvjhz?H9Hwy;q z(A6pkK_bdYWO2%^6B4mWPz=aj7(2WMfj#ZF)4ZQ0W!fz|nBKIZj`3bXSNB0wv?4L7 zEReJWxlcwo!%F*7cQ|R2GrASHx?c42T_NA@VWPS*9lh^nnUWY=+Z-$sx6t-3o{DK( ziEJf2;kFV|g?V})!cCzL%5E>@;%oR(h=a%ByW{dpw`k$M z$8VC|P{~f1CutG(j3HE)=WX?lwHL=}k(P1nL1=}7P#3;B9bBK0X-&O46g@5)9>a!i z5N&{hAjb5RP+|bF5#1y^w}*gf-yS=sWN5IB-O4(JJ3m~m$hd}U_B|XUJn2A~U_max zFY-H5B&CRfj&@{Hd=|0>^AfX+{IaXmi-NcNdDKV?aLq+g8ehLB)1qvbiB#IoQdI^_ zVqI#QMm5B$`nf?l5p^^*WWSi5cL}DHDP`)@CDRADX6Du(&K1jJ zFoZH3vJ$Giq?}dOGP1JnKnaa3u-Aun1vS4yhU{>)WZbFf*hWg=<*Z=QAvy4`*q(h8 zRslU5c?Is4Cg*r5=NyElYl8qz_q2KM!9&$-mT4{&4j!pyPsk1s!qF4egr5pri3imT zXc@BFG32z97F--j7mR^p(8;SN`cdR4gOwit1yEiAhZX1-*gR^}yVSP^H|DU-?ggI+ zlwOhKB965m$9b3cGt}#GeArL2iA6RbqP&IznVNiAg8p literal 1152 zcmZWnK~L0B5Ps9wc1!630!EA%uH~@R#G^5YL=T#kxZ%=-G^MXdH*FW*YmK|eWRl-ezKD9hKctiKEq-bP zMFkZLSf!!FVk347LszSvyv$Bx`RRy(fnH|Z=IF1U1@8W!t52(oWV|eN*8F^Wl%Kp-B1~%+FCNSjEOT(nEH#JBI?XkNE=T zTBTjLV8l>!@@a$S4)MgDyZP0{X;J)xuW!4O*6{{4{mu0?$&_|P^3Jli31`B38OXuK0=mU_{kAYtU z(nqCY2=55t;fe)3VGD#qz$}UsI=iDu*RY4AF)n117m^UTT&_3vZ#7K+1#CBQqau`Q3xkw{f+11|HeeezVfMI# zco{o%ZK6OPW^oYIb`WF}QKqCjL2y}yY3pe>^9WN)BD!27K_%oSi5(I|&yJuqNMZ;L zP?6KZb}Y@(Ewix?UBll-at?@`NX3S=xMbCo_}@jFZu_9Dok~sNX6x3gw*A*MzlO{X GIQ%z61p)*B diff --git a/src/main/python/bins.py b/src/main/python/bins.py index 78c8b6b..e81c4ff 100644 --- a/src/main/python/bins.py +++ b/src/main/python/bins.py @@ -1,11 +1,15 @@ class Bins: - def __init__(self, numrolls): - self.numberOfRolls = numrolls + def __init__(self, numDice): + self.numberOfDice = numDice + self.list = [] + def create_bin(self): - list = [] - for x in range(self.numberOfRolls, self.numberOfRolls * 6): - list.append(0) + for x in range(self.numberOfDice, self.numberOfDice * 6 + 1): + self.list.append(0) - return list + def increment_bin(self,sum): + index = sum - self.numberOfDice + checkthis = self.list[index] + 1 + self.list[index] = checkthis \ No newline at end of file diff --git a/src/main/python/dice.py b/src/main/python/dice.py index af3cafb..0ff5230 100644 --- a/src/main/python/dice.py +++ b/src/main/python/dice.py @@ -2,13 +2,12 @@ class Dice: - MAX = 6 - def __init__(self, numrolls): - self.numberOfRolls = numrolls + def __init__(self, numDice): + self.numberOfDice = numDice def tossAndSum(self): toss = 0 - for i in range(self.numberOfRolls): + for i in range(self.numberOfDice): toss = toss + random.randint(1, 6) return toss diff --git a/src/main/python/mainapplication.py b/src/main/python/mainapplication.py index 93444c7..527222e 100644 --- a/src/main/python/mainapplication.py +++ b/src/main/python/mainapplication.py @@ -1,4 +1,4 @@ from src.main.python.simulation import Simulation -sim = Simulation(10,500); +sim = Simulation(3,10000); sim.runSimulation() \ No newline at end of file diff --git a/src/main/python/simulation.py b/src/main/python/simulation.py index 24ee777..75f1215 100644 --- a/src/main/python/simulation.py +++ b/src/main/python/simulation.py @@ -3,23 +3,27 @@ class Simulation: - dice1 = Dice(2) - list = Bins(2) + def __init__(self, numberdice, numberrolls): self.numberOfDice = numberdice self.numberOfRolls = numberrolls + self.dice = Dice(self.numberOfDice) + self.bins = Bins(self.numberOfDice) def runSimulation(self): + self.bins.create_bin() for i in range(self.numberOfRolls): - dice1 = Dice(self.numberOfDice) - dicesum = dice1.tossAndSum() - bin(dicesum) - - def printStars(bin): - for x in bin: - print(x + " |") - print(bin[x] + " |") - print(bin[x / 1000000] + " |") - for y in range(1, bin[x]): - print("*") + dicesum = self.dice.tossAndSum() + self.bins.increment_bin(dicesum) + self.printStars(self.bins.list) + + + + def printStars(self, list): + for x in list: + stars = "" + for y in range(1, int(100*x/self.numberOfRolls)): + stars = stars + "*" + + print("sum: %-5s times: %-7s percent: %-9s : %s" % (list.index(x) + self.numberOfDice, x, x/self.numberOfRolls, stars)) diff --git a/src/test/python/dicey_test.py b/src/test/python/dicey_test.py index 6410d37..3781a89 100644 --- a/src/test/python/dicey_test.py +++ b/src/test/python/dicey_test.py @@ -1,22 +1,21 @@ import unittest from src.main.python.bins import Bins from src.main.python.dice import Dice -from src.main.python.simulation import runSimulation -from src.main.python.simulation import printStars +from src.main.python.simulation import Simulation class TestDiceyLab(unittest.TestCase): def test_createBin(self): - res = Bins(5).createBin() + res = Bins(5).create_bin() self.assertTrue(res, 150) def test_tossAndSum(self): - num = Dice().tossAndSum(3) + num = Dice(5).tossAndSum() self.assertTrue(num, int) - #def test_runSimulation(self): - #sim = runSimulation() - #self.assertTrue(sim, 3) + # def test_runSimulation(self): + # sim = Simulation(100, 100).runSimulation() + # self.assertTrue(sim, 3) #def test_printStars(self): #stars From 187e128bd4c1e79edba4e9d2b39cce4a06b72038 Mon Sep 17 00:00:00 2001 From: Ron Duwell Date: Mon, 2 Dec 2019 20:09:29 -0500 Subject: [PATCH 17/18] one million --- .idea/Python.DiceyLab.iml | 5 +- .idea/misc.xml | 2 +- .idea/workspace.xml | 87 ++++++------------ .../python/__pycache__/bins.cpython-38.pyc | Bin 852 -> 849 bytes .../python/__pycache__/dice.cpython-38.pyc | Bin 677 -> 674 bytes .../__pycache__/simulation.cpython-38.pyc | Bin 1270 -> 1267 bytes src/main/python/mainapplication.py | 2 +- 7 files changed, 30 insertions(+), 66 deletions(-) diff --git a/.idea/Python.DiceyLab.iml b/.idea/Python.DiceyLab.iml index 0a5fa1d..9b31378 100644 --- a/.idea/Python.DiceyLab.iml +++ b/.idea/Python.DiceyLab.iml @@ -2,10 +2,7 @@ - + - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index ffa9dcd..6c18255 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -15,5 +15,5 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7141878..4534ab2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,13 +3,7 @@ - - - - - - + + @@ -46,7 +45,7 @@ - + - - - @@ -169,6 +156,18 @@ + + - diff --git a/src/main/python/__pycache__/bins.cpython-38.pyc b/src/main/python/__pycache__/bins.cpython-38.pyc index 4d4a5fb85b1c8d8a72494d46523037f20fcf9c12..d87c2d90cca3e3b6b94f1eda6c6cf28bc01a164d 100644 GIT binary patch delta 54 zcmcb}c7=^Al$V!_0SG>=oyhe_&Q(9OIJKx)KQ}WwRo^AGIJ+djKtCn5Og}s|HQQn{ IJEIp90MQE(I{*Lx delta 51 zcmcb@c9D%Ml$V!_0SH94Oyqhb?W7-CoLW?@UzDGhQd*vxlcVpFTBaYKnwo9CnTyej F2>^ek4{ZPd diff --git a/src/main/python/__pycache__/dice.cpython-38.pyc b/src/main/python/__pycache__/dice.cpython-38.pyc index cf012665701ec5d9703da44cbc1bf6dfdaf5431d..4003cde5c1caa543fc25686f60e59ea47ab00b0f 100644 GIT binary patch delta 54 zcmZ3)x|EeGl$V!_0SKr4l$V!_0SH94Oys&F?W7-CoLW?@UzDGhQd*vxlcVpFTBaYKnwo9CnT2s7 FBLHl$4_5#H diff --git a/src/main/python/__pycache__/simulation.cpython-38.pyc b/src/main/python/__pycache__/simulation.cpython-38.pyc index f4589541c83ba48f4c318e0980883318d7099fb2..69847acfebee452d05b215506439e2a11d450bc5 100644 GIT binary patch delta 56 zcmey&`Hho1l$V!_0SHz{Jln_}%_!%sA6lGRRIHzynVqWdl3JWyl3$>ol3J!8o|>9% KvAL14h#3Ish!PY4 delta 53 zcmeyy`I(bDl$V!_0SH94Jl)70%_!}mA6lGRRIFc=pO;cvo|==R?~+=kAD)_;ZN9mM Hv4|M}t+x>2 diff --git a/src/test/python/dicey_test.py b/src/test/python/dicey_test.py index 3781a89..5118357 100644 --- a/src/test/python/dicey_test.py +++ b/src/test/python/dicey_test.py @@ -6,19 +6,15 @@ class TestDiceyLab(unittest.TestCase): def test_createBin(self): - res = Bins(5).create_bin() - self.assertTrue(res, 150) + bins = Bins(5) + bins.create_bin() + self.assertTrue(len(bins.list), 26) def test_tossAndSum(self): - num = Dice(5).tossAndSum() - self.assertTrue(num, int) - - # def test_runSimulation(self): - # sim = Simulation(100, 100).runSimulation() - # self.assertTrue(sim, 3) - - #def test_printStars(self): - #stars + for x in range(0, 10000): + num = Dice(5).tossAndSum() + self.assertTrue(num <= 30) + self.assertTrue(num >= 5)