Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/Binomial+Probability+Slot+Calculator+Example?V=133
QUERY_STRINGV=133
CONTENT_TYPE
DOCUMENT_URI/revision/Binomial+Probability+Slot+Calculator+Example
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.69.7.73
REMOTE_PORT32540
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR3.146.221.204
HTTP_CF_RAY87a7544e5e0b618d-ORD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTMozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; [email protected])
HTTP_CF_CONNECTING_IP3.146.221.204
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {Binomial Probability Slot Calculator Example} **Binomial\ Probability\ Slot\ Calculator\ Example**\n\nThis\ page\ is\ under\ development.\ Comments\ are\ welcome,\ but\ please\ load\ any\ \ comments\ in\ the\ comments\ section\ \ at\ the\ middle\ of\ the\ page.\ Please\ sign\ your\ user-name\ \ with\ the\ same\ courtesy\ that\ I\ will\ give\ you.\ \ Thanks,\[gold\]\n<<TOC>>\n**Introduction**\n\n----\n\[gold\]\ Here\ is\ some\ starter\ code\ for\ Binomial\ Probability\ Slot\ Calculator\ Example.\ The\ impetus\ for\ this\ calculator\ was\ checking\ some\ iching\ probabilities\ on\ the\ \[Chinese\ Iching\ Random\ Weather\ Predictions\].\ Its\ easy\ enough\ to\ plug\ in\ two\ formulas\ into\ the\ \[Slot_Calculator_Demo\]\ example.\ Most\ of\ the\ checked\ testcases\ involve\ flipping\ two\ sided\ objects\ like\ coins\ or\ popsicle\ sticks.\n\n----\nIn\ planning\ any\ software,\ it\ is\ advisable\ to\ gather\ a\ number\ of\ testcases\ to\ check\ the\ results\ of\ the\ program.\ The\ math\ for\ the\ testcases\ can\ be\ checked\ by\ pasting\ statements\ in\ the\ TCL\ console.\ Also,\ some\ of\ the\ pseudocode\ statements\ were\ checked\ in\ the\ google\ search\ engine\ which\ will\ take\ math\ expressions.\ The\ factorial\ procedure\ used\ below\ was\ posted\ by\ Suchenworth.\ Aside\ from\ the\ TCL\ calculator\ display,\ when\ one\ presses\ the\ report\ button\ on\ the\ calculator,\ one\ will\ have\ console\ show\ access\ \ to\ the\ binomial\ function.\ \[and\ the\ factorial\ (fact)\ function.\]\ \ \ \ \n\n----\nFor\ a\ system\ of\ 2\ sided\ sticks\ or\ coins\ of\ the\ number\ N,\ the\ probability\ of\ getting\ all\ zeros\ or\ ones\ would\ be:\n======\n\ set\ aa\ \[\ expr\ \{\ (1./(2**\$N))\}\ \]\ \;#\ generic\ TCL\ \n======\nFor\ three\ coins,\ the\ formula\ would\ be\ 1/(2**3)\ or\ 1/8.\n======\n\ set\ aa\ \[\ expr\ \{\ (1./(2**3)\}\ \]\ \ \n======\nFor\ six\ coins,\ the\ formula\ would\ be\ \ 1./(2**6)\ or\ 1/64\ \n======\n\ set\ aa\ \[\ expr\ \{\ (1./(2**6)\}\ \]\ \ \n======\nFor\ N\ coins,\ the\ probability\ that\ a\ one\ or\ zero\ \nwould\ show\ up\ on\ one\ of\ N\ coins\ would\ be\n======\n\ set\ aa\ \[\ expr\ \{\ (1.-(1./(2**\$N)))\}\ \]\n======\ \n\n----\n\ \ \ \ \ \ \ \nThe\ testcase\ 1\ was\ 6\ choose\ 2.\ The\ sample\ size\ was\ 2**6\ or\ 64.\n======\n\ set\ gg\ \[\ expr\ \{\ 2**6\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 6\ coins\ was\ 1/(2**6)\ or\ 1/64.\n======\n\ set\ rr\ \[\ expr\ \{\ 1./(2**6)\ \}\ \]\n======\nThe\ answer\ for\ 6\ coins\ choose\ 2\ was\ 0.234\n\n----\n\nThe\ testcase\ 2\ was\ 3\ choose\ 2.\ The\ sample\ size\ was\ 2**3\ or\ 8.\n======\n\ set\ kk\ \[\ expr\ \{\ 2**3\ \}\ \]\n======\nThe\ probability\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 3\ coins\ was\ 1/(2**3)\ or\ 1/8.\n======\n\ set\ jj\ \[\ expr\ \{\ 1./(2**3)\ \}\ \]\n======\nThe\ answer\ for\ 3\ coins\ choose\ 2\ was\ 0.375.\n\n----\ \n\nThe\ testcase\ 3\ was\ 12\ choose\ 2.\ The\ sample\ size\ was\ 2**10\ or\ 4096.\n======\n\ set\ xx\ \[\ expr\ \{\ 2**12\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 12\ coins\ was\ 1/(2**12)\ or\ 1/4096\ or\ \ 2.441E-4\ \n======\n\ set\ vv\ \[\ expr\ \{\ 1./(2**12)\ \}\ \]\n======\nThe\ answer\ for\ 12\ choose\ 2\ was\ 0.01611.\n\n----\n**Session\ from\ console**\n======\n\ \ \ \ 1%\ set\ rr\ \[\ expr\ \{\ 1./(2**12)\ \}\ \]\n\ \ \ \ \ \ 0.000244140625\n\ \ \ \ 2%\ set\ gg\ \[\ expr\ \{\ 2**12\ \}\ \]\n\ \ \ \ 4096\n\ \ \ \ 3%\ set\ rr\ \[\ expr\ \{\ 1./(2**6)\ \}\ \]\n\ \ \ \ 0.015625\n\ \ \ \ 4%\ set\ gg\ \[\ expr\ \{\ 2**6\ \}\ \]\n\ \ \ \ 64\n======\n----\ \n\nThe\ testcase\ 4\ was\ 4\ coins\ choose\ 2.\ The\ sample\ size\ was\ 2**4\ or\ 16.\n======\n\ set\ xx\ \[\ expr\ \{\ 2**4\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails.\ from\ 4\ coins\ was\ 1/(2**4)\ or\ 1/16\ or\ \ .0625\n======\n\ set\ vv\ \[\ expr\ \{\ 1./(2**4)\ \}\ \]\n======\nThe\ answer\ for\ 4\ coins\ choose\ 2\ was\ 0.375.\n\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \nThe\ testcase\ 5\ was\ 9\ coins\ choose\ 2.\ The\ sample\ size\ was\ 2**9\ or\ 512.\n======\n\ set\ xx\ \[\ expr\ \{\ 2**9\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 9\ coins\ was\ 1/(2**9)\ or\ 1/512\ or\ \ .00195\ \n======\n\ set\ vv\ \[\ expr\ \{\ 1./(2**9)\ \}\ \]\n======\nThe\ answer\ for\ 9\ coins\ choose\ 2\ was\ 0.0703\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \n----\n**Console\ session**\ \n======\n\ \ \ \ 1%\ set\ xx\ \[\ expr\ \{\ 2**4\ \}\ \]\n\ \ \ \ 16\n\ \ \ \ 2%\ set\ vv\ \[\ expr\ \{\ 1./(2**4)\ \}\ \]\n\ \ \ \ 0.0625\n\ \ \ \ 3%\ binom\ 4\ 2\ 2\n\ \ \ \ 0.375\n\ \ \ \ 4%\ set\ xx\ \[\ expr\ \{\ 2**9\ \}\ \]\n\ \ \ \ 512\n\ \ \ \ 5%\ set\ vv\ \[\ expr\ \{\ 1./(2**9)\ \}\ \]\n\ \ \ \ 0.001953125\n\ \ \ \ 6%\ binom\ 9\ 2\ 2\n\ \ \ \ 0.07031251\n\ \ \ \ %\ fact\ 9\n\ \ \ \ \ \ 362880\n======\ \ \ \ \ \ \ \ \ \n----\ \ \ \nThe\ testcase\ 6\ was\ 20\ coins\ choose\ 10.\ The\ sample\ size\ was\ 2**20\ or\ 1,048,576.\n======\n\ set\ zz\ \[\ expr\ \{\ 2**20\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 20\ coins\ was\ 1/(2**20)\ or\ 1/1,048,576\ \ or\ 9.536E-7.\ \n======\n\ set\ xx\ \[\ expr\ \{\ 1./(2**20)\ \}\ \]\n======\nThe\ answer\ for\ 20\ coins\ choose\ 10\ was\ 0.1762.\n\n----\n\nThe\ testcase\ 7\ was\ 100\ coins\ choose\ 50.\nThe\ sample\ size\ was\ 2**100\ or\ 1.26765E+30.\ngoogle(2\ **\ 100)\ =\ 1.2676506\ ×\ 10E30\n======\ \n\ \ set\ zz\ \[\ expr\ \{\ 2**100\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails\nfrom\ 20\ coins\ was\ 1/(2**100)\ or\ 1/1.26765E+30\ \ or\ 7.888609E-31\ngoogle(1\ /\ (2\ **\ 100))\ =\ 7.88860905\ ×\ 10-31.\n======\n\ set\ xx\ \[\ expr\ \{\ 1./(2**100)\ \}\ \]\n======\nThe\ answer\ for\ 100\ coins\ choose\ 50\ was\ 0.013843748310702326.\n\n**Console\ session\ \ compared\ to\ stattrek.com**\n======\n\ \ \ \ 2%\ binom\ 100\ 50\ 2\n\ \ \ \ 0.07978845608028655\ \ \ \ \ \ \ \ \ \ \ stattrek(\ 0.0795892373871788\ )\ \ \ \ \ \n\ \ \ \ 3%\ \ binom\ 100\ 60\ 2\n\ \ \ \ 0.010872519679731506\ \ \ \ \ \ \ \ \ \ stattrek(0.010843866711638)\ \ \ \n\ \ \ \ 4%\ binom\ 100\ 70\ 2\n\ \ \ \ 2.3243440318642605e-5\ \ \ \ \ \ \ \ \ stattrek(\ 2.31706905801352E-05\ )\ \ \ \ \ \ \n\ \ \ \ 5%\ binom\ 100\ 80\ 2\ \n\ \ \ \ 4.229044215516387e-10\ \ \ \ \ \ \ \ \ stattrek(\ 4.22816326760158E-10\ )\ \ \ \n\ \ \ \ 6%\ binom\ 100\ 90\ 2\ \ \n\ \ \ \ 1.3656690823232337e-17\ \ \ \ \ \ \ \ stattrek(\ 1.36554263874631E-17)\n\ \ \ \ 7%\ binom\ 100\ 95\ 2\ \ \n\ \ \ \ 5.939398609386625e-23\ \ \ \ \ \ \ \ \ stattrek(\ 5.93913811790451E-23)\n\ \ \ \ 8%\ binom\ 100\ 99\ 2\n\ \ \ \ 7.888675454251962e-29\ \ \ \ \ \ \ \ \ stattrek(7.88860905221012E-29)\ \ \n======\ \ \ \ \ \ \ \ \ \n----\n\nThe\ testcase\ 8\ was\ 120\ coins\ choose\ 50.1.329227E+36.\ The\ sample\ size\ was\ 2**120\ or\ 1.329227E+36.\ google(2\ **\ 120)\ =\ 1.329228\ ×\ 10E36\n======\n\ set\ zz\ \[\ expr\ \{\ 2**120\ \}\ \]\ \n======\nThe\ probability\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 120\ coins\ was\ 1/(2**120)\ or\ 1/\ 1.329227E+36\ or\ 7.5231E-37\ google(1\ /\ (2\ **\ 120))\ =\ 7.52316385\ ×\ 10-37\n======\n\ set\ xx\ \[\ expr\ \{\ 1./(2**120)\ \}\ \]\n======\nThe\ answer\ for\ 120\ coins\ choose\ 50\ was\ 0.013843748310702326,\ omparable\ to\ stattrek(0.0138138412069122).\n======\n\ \ \ \ \ #console\ session\ \n\ \ \ \ \ 12%\ binom\ 120\ 50\ 2\n\ \ \ \ \ 0.013843748310702326\ \ \ \n======\ \ \ \ \ \n----\n**Extra\ Credit**\n\nFor\ a\ system\ of\ one\ die\ with\ kk\ sides\ of\ the\ number\ N\ tosses,\ the\ sample\ size\ would\ be:\n======\n\ set\ aa\ \[\ expr\ \{\ (\$kk**\$N)\}\ \]\ \n======\ \ \nFor\ example,\ a\ 6\ sided\ die\ with\ 2\ tosses\ would\ have\ a\ sample\ size\ of\ 6**2\ or\ 36.\n======\n\ set\ aa\ \[\ expr\ \{\ (\ 6**2\ )\}\ \]\ \n======\nThe\ probability\ of\ two\ dice\ having\ the\ same\ face\ like\ snake\ eyes\ (1:1)\ on\ one\ throw\ \ is\ 1/(sample\ size)\ or\ 1/36.\ \n======\n\ set\ pp\ \[\ expr\ \{\ 1./(6**2)\ \}\ \]\n======\n----\nThe\ following\ sums\ the\ numbers\ on\ two\ faces.\ For\ 2\ dice\ of\ 6\ sides,\ the\ probability\ of\ a\ number\ 7\ coming\ up\ is\ 0.1666.\ In\ pseudocode\ statements,\ the\ probability\ of\ two\ dice\ landing\ with\ sum\ 7\ would\ be\ the\ number\ of\ combinations\ that\ add\ up\ to\ seven\ over\ the\ number\ of\ \ all\ possible\ combinations\ from\ throwing\ 2\ dice.\ Such\ a\ \$list\ can\ generated\ in\ the\ auxillary\ eTCL\ script\ at\ the\ bottom\ of\ page.\ \n======\n\ \ \ prob.\ pseudocode\ \ \ =\ nom\ (\$list)\ /\ denom\ (\ \$list)\ \n\ \ \ prob.\ pseudocode\n\ \ \ =\ llength\ \[lsearch\ -all\ \$list\ 7\ \]\ /\ \[llength\ \$list\ \]\n\ \ \ prob.\ pseudocode\n\ \ \ =\ \[llength\ \[lsearch\ -all\ \$list\ 7\ \]\]\ /\ \[llength\ \$list\ \]\n======\nThis\ would\ find\ our\ probability\ of\ throw\ 7\ on\ a\ one\ time\ basis.\ For\ the\ calculator,\ this\ process\ could\ be\ generalized\ into\ a\ subroutine\ that\ generated\ a\ list\ for\ 2\ to\ N\ sides:\ list(N),\ an\ expected\ dice\ throw\ as\ \$facenumber,\ counted\ the\ number\ of\ throws\ showing\ \$facenumber\ in\ list(N),\ and\ counted\ all\ the\ elements\ in\ the\ list(N).\ \n======\n\ \ prob.\ pseudocode\ \ \ =\ \n\ \ \[llength\ \[lsearch\ -all\ \$list(N)\ \$facenumber\ \]\]\ /\ \[llength\ \$list(N)\ \]\n======\nAlso,\ another\ foreach\ loop\ in\ the\ list\ generator\ could\ probably\ generate\ the\ possible\ throws\ of\ three\ dice.\n----\ \ \n\n**Screenshots\ Section**\n\ \ \n\[http://farm5.static.flickr.com/4100/4826856340_d43cb36805.jpg\]\n\n\[http://farm5.static.flickr.com/4102/4830809174_47303eaa2c.jpg\]\n\n\n\[http://farm5.static.flickr.com/4092/4840912575_32c4402fa5.jpg\]\ \n\[http://farm5.static.flickr.com/4149/4841520100_c94c594994.jpg\]\ \n\n\[http://farm5.static.flickr.com/4092/4840912575_32c4402fa5.jpg\]\n\[http://farm5.static.flickr.com/4149/4841520100_c94c594994.jpg\]\ \n\n\n----\n**Comments\ Section**\nPlease\ place\ any\ comments\ here,\ Thanks.\n\n\[gold\]\ Changes.\n\n\ \n----\n**References**\n\n\ \ \ *\ \[factorial\]\n\ \ \ *\ \[Slot_Calculator_Demo\]\n\ \ \ *\ http://www.knowyourluck.com/coins3u.html\ (currently\ 404)\n\ \ \ *\ http://www.learning.com/pdfs/et/activity-35-cointoss.pdf\n\ \ \ *\ http://stattrek.com/Tables/Binomial.aspx\ Binomial\ Distribution\ Calculator\n\ \ \ *\ \[Sample\ Math\ Programs\]\ modified\ \[PSE\}\ operation\ tables\ to\ generate\ throw\ do-loops\n\ \ \ *\ http://hyperphysics.phy-astr.gsu.edu/hbase/math/dice.html\ Statistics\ of\ Dice\ Throw\ \n\ \ \ *\ http://wizardofodds.com/gambling/dice.html\ Dice\ Probability\ basics\n\ \ \ *\ http://www.cobalt.chem.ucalgary.ca/ziegler/educmat/chm386/rudiment/mathbas/probab.htm\ Probability\n\ \ \ *\ http://gwydir.demon.co.uk/jo/probability/calcinfo.htm\ Calculating\ probabilities\ of\ throwing\ two\ dice\n\n\n\ The\ Math\ Forum,Date:\ 05/16/99\ at\ 16:24:04\n\ From:\ Doctor\ Anthony\n\ Subject:\ Re:\ Probability\ dealing\ with\ combinations\ of\ dice\n\n\ The\ Math\ Forum,Date:\ 12/05/2001\ at\ 00:36:56\n\ From:\ Doctor\ Jeremiah\n\ Subject:\ Re:\ Probability\ of\ dicehttp://wiki.tcl.tk/13243\n\nThrowing\ Two\ Dice\n\n\ \ \ *\ \[throw\ a\ dice\]\n\ \ \ *\ \[Dice\]\n\nGoogle\ Answers\ Probability\ of\ Coin\ Flip.mht\n\ \n2\ Dice\ Rolls\ Probability-Statistics\ -\ Separate.mht\nhttp://mathforum.org/library/drmath/view/56627.html\n\n**appendix\ TCL\ programs**\n***Pretty\ Print\ Version***\ \n\n======\n\ \ \ \ #\ Pretty\ Print\ version\ from\ autoindent\ and\ ased\ editor\n\ \ \ \ #\ written\ on\ Windows\ XP\ on\ eTCL\n\ \ \ \ #\ working\ under\ TCL\ version\ 8.5.6\ and\ eTCL\ 1.0.1\n\ \ \ \ #\ gold\ on\ TCL\ WIKI\ ,\ 21Jul2010\n\ \ package\ require\ Tk\n\ \ \ \ frame\ .frame\ -relief\ flat\ -bg\ aquamarine4\n\ \ \ \ pack\ .frame\ -side\ top\ -fill\ y\ -anchor\ center\n\ \ \ \ \n\ \ \ \ set\ names\ \{\{\}\ N_coins:\ heads:\ \{sides:\}\ \{sample:\}\ \{1/sample:\}\ \{answer:\}\ 1/sample:\}\n\ \ \ \ foreach\ i\ \{1\ 2\ 3\ 4\ 5\ 6\ \}\ \{\n\ \ \ \ \ \ \ \ label\ .frame.label\$i\ -text\ \[lindex\ \$names\ \$i\]\ -anchor\ e\n\ \ \ \ \ \ \ \ entry\ .frame.entry\$i\ -width\ 35\ -textvariable\ side\$i\n\ \ \ \ \ \ \ \ grid\ .frame.label\$i\ .frame.entry\$i\ -sticky\ ew\ -pady\ 2\ -padx\ 1\n\ \ \ \ \}\n\ \ \ \ proc\ about\ \{\}\ \{\n\ \ \ \ \ \ \ \ set\ msg\ \"Calculator\ for\ binomial\ probabliity.\n\ \ \ \ \ \ \ \ from\ TCL\ WIKI,\n\ \ \ \ \ \ \ \ written\ on\ eTCL\ \"\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ tk_messageBox\ -title\ \"About\"\ -message\ \$msg\n\ \ \ \ \}\n\ \ \ \ proc\ pi\ \{\}\ \{expr\ acos(-1)\}\n\ \ \ \ \n\ \ \ \ proc\ fact\ n\ \{expr\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ \ \ \ \$n<2?\ 1:\n\ \ \ \ \ \ \ \ \ \ \ \ \$n>20?\ pow(\$n,\$n)*exp(-\$n)*sqrt(2*acos(-1)*\$n):\n\ \ \ \ \ \ \ \ \ \ \ \ wide(\$n)*\[fact\ \[incr\ n\ -1\]\]\}\n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ proc\ binomialprobabilty\ \{\ aa\ \ bb\ \ cc\ dd\ \ ee\ \ \ \}\ \{\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ #set\ aa\ 6\n\ \ \ \ \ \ \ \ #set\ bb\ 4\n\ \ \ \ \ \ \ \ #set\ cc\ 2\n\ \ \ \ \ \ \ \ set\ sidex\ \$cc\n\ \ \ \ \ \ \ \ set\ aa\ \[\ expr\ \{\ int(\$aa)\ \}\ \]\n\ \ \ \ \ \ \ \ set\ cc\ \[\ expr\ \{\ int(\$bb)\ \}\ \]\n\ \ \ \ \ \ \ \ set\ bb\ \[\ expr\ \{\ \$aa-\$cc\ \}\ \]\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ term1\ \[\ fact\ \$aa\ \]\n\ \ \ \ \ \ \ \ set\ term2\ \[\ fact\ \$bb\ \]\n\ \ \ \ \ \ \ \ set\ term3\ \[\ fact\ \$cc\ \]\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ sample\ \[\ expr\ \{\ \$sidex**\$aa\}\ \]\n\ \ \ \ \ \ \ \ set\ binprob\ \[\ expr\ \{\ (\$term1*1.)/(\$term2*\$term3*\$sample*1.)\ \ \}\ \]\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ return\ \ \$binprob\ \ \;\n\ \ \ \ \ \ \ \ \n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ proc\ binom\ \{\ aa\ \ bb\ \ cc\ \ \ \ \}\ \{\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ #set\ aa\ 6\n\ \ \ \ \ \ \ \ #set\ bb\ 4\n\ \ \ \ \ \ \ \ #set\ cc\ 2\n\ \ \ \ \ \ \ \ set\ sidex\ \$cc\n\ \ \ \ \ \ \ \ set\ aa\ \[\ expr\ \{\ int(\$aa)\ \}\ \]\n\ \ \ \ \ \ \ \ set\ cc\ \[\ expr\ \{\ int(\$bb)\ \}\ \]\n\ \ \ \ \ \ \ \ set\ bb\ \[\ expr\ \{\ (\$aa-\$cc)\ \}\ \]\n\ \ \ \ \ \ \ \ set\ term1\ \[\ fact\ \$aa\ \]\n\ \ \ \ \ \ \ \ set\ term2\ \[\ fact\ \$bb\ \]\n\ \ \ \ \ \ \ \ set\ term3\ \[\ fact\ \$cc\ \]\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ sample\ \[\ expr\ \{\ \$sidex**\$aa\}\ \]\n\ \ \ \ \ \ \ \ set\ binprob\ \[\ expr\ \{\ (\$term1*1.)/(\$term2*\$term3*\$sample*1.)\ \ \}\ \]\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ return\ \ \$binprob\ \ \;\n\ \ \ \ \ \ \ \ \n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ proc\ pol\ \{\ xx1\ yy1\ xx3\ yy3\ xx2\ \ \ \}\ \{\n\ \ \ \ \ \ \ \ return\ \[expr\ \{\ \ (((\$xx2-\$xx1)*(\$yy3-\$yy1))/(\$xx3-\$xx1))+\ \$yy1\ \}\ \]\ \;\}\n\ \ \ \ \n\ \ \ \ proc\ calculate\ \{\ \ \ \ \ \}\ \{\n\ \ \ \ \ \ \ \ global\ answer2\ \ \n\ \ \ \ \ \ \ \ global\ side1\ side2\ side3\ side4\ side5\ side6\n\ \ \ \ \ \ \ \ set\ answer2\ \ \[\ binomialprobabilty\ \ \$side1\ \$side2\ \$side3\ \$side4\ \$side5\ \ \]\n\ \ \ \ \ \ \ \ set\ side4\ \[\ expr\ \{\ \$side3**\$side1\ \ \ \ \ \}\ \]\n\ \ \ \ \ \ \ \ set\ side5\ \[\ expr\ \{\ 1./\ (\$side3**\$side1)\ \ \ \ \ \}\ \]\n\ \ \ \ \ \ \ \ set\ side6\ \$answer2\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ pi5\ \[pi\]\n\ \ \ \ \ \ \ \ if\ \{\$answer2\ >=\ \$pi5\}\ \{\ set\ error5\ \ \ \[expr\ \{100.*\$answer2/\$pi5-100.\}\]\ \ \ \}\n\ \ \ \ \ \ \ \ if\ \{\$answer2\ <=\ \$pi5\}\ \{\ set\ error5\ \ \ \[expr\ \{100.*\$pi5/\$answer2-100.\}\]\ \ \ \}\n\ \ \ \ \ \ \ \ #\$x\ insert\ 1.0\ \"\ %\ error\ \$error5\ \"\n\ \ \ \ \ \ \ \ #\$t\ insert\ 1.0\ \"\ %\ error\ \ \$error5\ \"\n\ \ \ \ \ \ \ \ \n\ \ \ \ \}\n\ \ \ \ proc\ fillup\ \{aa\ bb\ cc\ dd\ ee\ ff\ \}\ \{\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ .frame.entry1\ insert\ 0\ \"\$aa\"\n\ \ \ \ \ \ \ \ .frame.entry2\ insert\ 0\ \"\$bb\"\n\ \ \ \ \ \ \ \ .frame.entry3\ insert\ 0\ \"\$cc\"\n\ \ \ \ \ \ \ \ .frame.entry4\ insert\ 0\ \"\$dd\"\n\ \ \ \ \ \ \ \ .frame.entry5\ insert\ 0\ \"\$ee\"\n\ \ \ \ \ \ \ \ .frame.entry6\ insert\ 0\ \"\$ff\ \"\n\ \ \ \ \ \ \ \ \n\ \ \ \ \}\n\ \ \ \ proc\ clearx\ \{\}\ \{\n\ \ \ \ \ \ \ \ foreach\ i\ \{1\ 2\ 3\ 4\ 5\ 6\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ .frame.entry\$i\ delete\ 0\ end\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ proc\ reportx\ \{\}\ \{\n\ \ \ \ \ \ \ \ console\ show\;\n\ \ \ \ \ \ \ \ puts\ \"\n\ \ \ \ \ \ \ \ The\ binom\ function\ takes\n\ \ \ \ \ \ \ \ three\ \ quantities.\n\ \ \ \ \ \ \ \ The\ points\ are\ aa,bb\ ,cc.\n\ \ \ \ \ \ \ \ The\ input\ order\ of\ the\ 3\ items\n\ \ \ \ \ \ \ \ is\ \ N_coins\ heads\ sides\n\ \ \ \ \ \ \ \ and\ solving\ for\ binomial\ probability.\n\ \ \ \ \ \ \ \ eg.\ binom\ 9\ 2\ 2\ gives\ 0.0703\n\ \ \ \ \ \ \ \ \"\n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ frame\ .buttons\ -bg\ aquamarine4\n\ \ \ \ \n\ \ \ \ ::ttk::button\ .calculator\ -text\ \"Solve\"\ -command\ \{\ calculate\ \ \ \}\n\ \ \ \ \n\ \ \ \ ::ttk::button\ .test2\ -text\ \"Testcase1\"\ -command\ \{\ clearx\;fillup\ 6.\ 2.\ 2.\ 64.\ \ .0156\ .234375\ \}\n\ \ \ \ ::ttk::button\ .test3\ -text\ \"Testcase2\"\ -command\ \{\ clearx\;fillup\ \ 3.\ 2.\ 2.\ 8.\ \ .125\ .375\ \}\n\ \ \ \ ::ttk::button\ .test4\ -text\ \"Testcase3\"\ -command\ \{\ clearx\;fillup\ 12.\ 2.\ 2.\ 4096.\ \ 2.4E-4\ .01611\ \}\n\ \ \ \ ::ttk::button\ .clearallx\ -text\ clear\ -command\ \{clearx\ \ \}\n\ \ \ \ ::ttk::button\ .about\ -text\ about\ -command\ about\n\ \ \ \ ::ttk::button\ .cons\ -text\ report\ -command\ \{\ reportx\ \}\n\ \ \ \ ::ttk::button\ .exit\ -text\ exit\ -command\ \{exit\}\n\ \ \ \ pack\ .calculator\ \ -in\ .buttons\ -side\ top\ -padx\ 10\ -pady\ 5\n\ \ \ \ \n\ \ \ \ pack\ \ .clearallx\ .cons\ .about\ .exit\ .test4\ .test3\ \ .test2\ \ \ -side\ bottom\ -in\ .buttons\n\ \ \ \ grid\ .frame\ .buttons\ -sticky\ ns\ -pady\ \{0\ 10\}\n\ \ \ \ .\ configure\ -background\ aquamarine4\ -highlightcolor\ brown\ -relief\ raised\ -border\ 30\n\ \ \ \ wm\ title\ .\ \"Binomial\ Probablity\ Slot\ Calculator\ Example\ \"\n======\n\n****Auxillary\ programs***\ \n\nHere's\ searching\ through\ a\ list\ of\ thrown\ dice\ combos\nfor\ probability.\ The\ worker\ bee\ is\n======\n\ \[\ lsearch\ -all\ \[\ listofnn\ \$nn\ \]\ \$facen\ \]\n\ \$facen\ is\ the\ sum\ of\ a\ 2-dice\ throw\ like\ 7.\n\ \$nn\ is\ the\ number\ of\ sides,eg\ 6.\n======\nSubroutine\ is\ invoked\ by\ a\ foreach\ procedure\nfor\ probability,\ which\ would\ be\ number\ of\ thrown\ 7's\nover\ all\ possible\ throws.\ Drop\ (-all)\ and\ lose\ all,\nreturning\ only\ one\ position\ of\ \"7\"\ in\ list.\n----\n**Console\ program\ \ for\ two\ 6-sided\ dice**\n======\ \n\ \ \ \ \ \ #\ prob.\ subroutines\ for\ two\ 6-sided\ dice\n\ \ \ \ \ \ #\ throw\ of\ 7\ etc.\n\ \ \ \ \ \ proc\ listofnn\ \{\ nn\ \}\ \{\n\ \ \ \ \ \ set\ lister\ \[list\ \]\n\ \ \ \ \ \ for\ \{\ set\ i\ 1\ \}\ \{\ \$i\ <=\ \$nn\ \}\ \ \{\ incr\ i\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ lappend\ lister\ \$i\n\ \ \ \ \ \ \}\n\ \ \ \ \ \ set\ i\ 0\n\ \ \ \ \ \ while\ \{\ \[\ incr\ i\ \]\ <=\ \$nn\ \}\ \{\n\ \ \ \ \ \ \ \ \ foreach\ item\ \$lister\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ append\ listofnn\ \"\ \[\ expr\ \{\$item+\$i\}\ \]\"\n\ \ \ \ \ \ \ \ \ \}\n\ \n\ \ \ \ \ \ \}\n\ \ \ \ \ return\ \$listofnn\n\ \ \ \ \ \ \}\n\ \ \ \ \ proc\ calculation\ \{\ nn\ \ facen\ \}\ \ \{\ \ \ \n\ \ \ \ \ set\ ee\ \[llength\ \[\ listofnn\ \$nn\ \]\]\n\ \ \ \ \ set\ kk\ \[\ llength\ \[\ lsearch\ -all\ \[\ listofnn\ \$nn\ \]\ \$facen\ \]\ \]\n\ \ \ \ \ set\ prob\ \[\ expr\ \{\ (\$kk*1.)\ /\ \$ee\ \ \}\ \]\n\ \ \ \ \ return\ \$prob\n\ \ \ \ \ \}\n\ \ \ \ console\ show\n\ \ \ \ \ \ \ \ \ \ set\ limit\ 12\n\ \ \ \ \ \ \ \ \ \ for\ \{\ set\ i\ 1\ \}\ \{\ \$i\ <=\ \$limit\ \}\ \ \{\ incr\ i\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ lappend\ listxxx\ \$i\ \n\ \ \ \ \ \ \ \ \ \ lappend\ listxxx\ \[\ calculation\ 6\ \$i\ \]\n\ \ \ \ \ \ \ \ \ \ puts\ \"\ \$i\ \[\ calculation\ 6\ \$i\ \]\ \"\n\ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ puts\ \$listxxx\n======\n\ output\ plotted\ in\ jpg\ above\n\ 1\ 0.0\ \n\ 2\ 0.027777777777777776\ \n\ 3\ 0.05555555555555555\ \n\ 4\ 0.08333333333333333\ \n\ 5\ 0.1111111111111111\ \n\ 6\ 0.1388888888888889\ \n\ 7\ 0.16666666666666666\ \n\ 8\ 0.1388888888888889\ \n\ 9\ 0.1111111111111111\ \n\ 10\ 0.08333333333333333\ \n\ 11\ 0.05555555555555555\ \n\ 12\ 0.027777777777777776\ \n\ \ \ \ #end\n\n\ \ \ \ ------\n======\n\ \ \ \ \ #\ written\ on\ Windowws\ XP\ on\ eTCL\ \n\ \ \ \ \ #\ working\ under\ TCL\ version\ 8.5.6\ and\ eTCL\ 1.0.1\ \n\ \ \ \ \ #\ gold\ on\ TCL\ WIKI\ ,\ 21Jul2010\n\ \ \ \ \ #\ find\ probability\ of\ 7\ on\ 2\ 6-sided\ dice.\n\n\ \ \ \ \ \ proc\ listofnn\ \{\ nn\ \}\ \{\n\ \ \ \ \ \ set\ lister\ \[list\ \]\n\ \ \ \ \ \ for\ \{\ set\ i\ 1\ \}\ \{\ \$i\ <=\ \$nn\ \}\ \ \{\ incr\ i\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ lappend\ lister\ \$i\n\ \ \ \ \ \ \}\n\ \ \ \ \ \ set\ i\ 0\n\ \ \ \ \ \ #puts\ \$lister\n\ \ \ \ \ \ while\ \{\ \[\ incr\ i\ \]\ <=\ \$nn\ \}\ \{\n\ \ \ \ \ \ \ \ \ foreach\ item\ \$lister\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ append\ listofnn\ \"\ \[\ expr\ \{\$item+\$i\}\ \]\"\n\ \ \ \ \ \ \ \ \ \}\n\ \n\ \ \ \ \ \ \}\n\ \ \ \ \ return\ \$listofnn\n\ \}\n\n\ \ \ \ console\ show\n\ \ \ \ #not\ efficient\ code\ here.\n\ \ \ \ #trying\ to\ show\ evolution\n\ \ \ \ #from\ pseudocode\n\ \ \ \ puts\ \"\ prob.\ pseudocode\ \ \ =\ nom\ (\\\$list)\ \\/\ denom\ (\ \\\$list)\ \"\n\n\ \ \ \ puts\ \"pseudocode:find\ all\ possible\ combinations\ from\ throwing\ 2\ dice\"\n\ \ \ \ puts\ \[\ listofnn\ 6\ \]\n\ \ \ \ puts\ \"pseudocode:\ find\ length\ of\ list\"\n\ \ \ \ puts\ \"pseudocode:\\\[llength\ \\\$list\ \\\]\"\n\ \ \ \ puts\ \[llength\ \[\ listofnn\ 6\ \]\]\n\ \ \ \ set\ ee\ \[llength\ \[\ listofnn\ 6\ \]\]\n\ \ \ \ puts\ \"pseudocode:\ find\ positions\ of\ 7\ in\ list\"\n\ \ \ \ puts\ \"prob.\ pseudocode\ \ \ \\=\ \\\[lsearch\ -all\ \\\$list\ 7\ \\\]\ \"\n\n\ \ \ \ puts\ \[\ lsearch\ -all\ \[\ listofnn\ 6\ \]\ 7\ \]\n\ \ \ \ puts\ \"pseudocode:\ count\ number\ of\ throws\ of\ 7\"\n\ \ \ \ puts\ \"\ prob.\ pseudocode\ \ \ \\=\ llength\ \\\[lsearch\ -all\ \\\$list\ 7\ \\\]\ \"\n\n\ \ \ \ puts\ \[\ llength\ \[\ lsearch\ -all\ \[\ listofnn\ 6\ \]\ 7\ \]\ \]\n\ \ \ \ set\ kk\ \[\ llength\ \[\ lsearch\ -all\ \[\ listofnn\ 6\ \]\ 7\ \]\ \]\n\ \ \ \ \ puts\ \"prob.\ pseudocode\ \ \ =\ \\\[llength\ \\\[lsearch\ -all\ \\\$list\ 7\ \\\]\\\]\ \\/\ \\\[llength\ \\\$list\ \\\]\"\n\ \ \ \ #not\ efficient\ code\ here.\n\ \ \ \ #trying\ to\ show\ evolution\n\ \ \ \ #from\ pseudocode\n\n\ \ \ \ set\ prob\ \[\ expr\ \{\ (\$kk*1.)\ /\ \$ee\ \ \}\ \]\n\ \ \ \ puts\ \$prob\n\ \ \ \ #end\ of\ deck\n======\n\ \ \ printed\ output\ of\ deck\n\ \ prob.\ pseudocode\ \ \ =\ nom\ (\$list)\ /\ denom\ (\ \$list)\ \n\ \ pseudocode:find\ all\ possible\ combinations\ from\ throwing\ 2\ dice\n\ \ \ 2\ 3\ 4\ 5\ 6\ 7\ 3\ 4\ 5\ 6\ 7\ 8\ 4\ 5\ 6\ 7\ 8\ 9\ 5\ 6\ 7\ 8\ 9\ 10\ 6\ 7\ 8\ 9\ 10\ 11\ 7\ 8\ 9\ 10\ 11\ 12\n\ \ pseudocode:\ find\ length\ of\ list\n\ \ pseudocode:\[llength\ \$list\ \]\n\ \ 36\n\ \ pseudocode:\ find\ positions\ of\ 7\ in\ list\n\ \ prob.\ pseudocode\ \ \ =\ \[lsearch\ -all\ \$list\ 7\ \]\ \n\ \ 5\ 10\ 15\ 20\ 25\ 30\n\ \ pseudocode:\ count\ number\ of\ throws\ of\ 7\n\ \ prob.\ pseudocode\ \ \ =\ llength\ \[lsearch\ -all\ \$list\ 7\ \]\ \n\ \ 6\n\ \ prob.\ pseudocode\ \ \ =\ \[llength\ \[lsearch\ -all\ \$list\ 7\ \]\]\ /\ \[llength\ \$list\ \]\n\ \ 0.16666666666666666\n======\n\ \ \ \n----\n======\n\ \ \ \ \ #\ written\ on\ Windowws\ XP\ on\ eTCL\ \n\ \ \ \ \ #\ working\ under\ TCL\ version\ 8.5.6\ and\ eTCL\ 1.0.1\ \n\ \ \ \ \ #\ gold\ on\ TCL\ WIKI\ ,\ 21Jul2010\n\ \ \ \ \ frame\ .frame\ -relief\ flat\ -bg\ aquamarine4\n\ \ \ \ \ \ pack\ .frame\ -side\ top\ -fill\ y\ -anchor\ center\n\n\ \ \ \ set\ names\ \{\{\}\ \{throw:\}\ \{N_sides:\}\ \{No_dice:\}\ \{sample:\}\ \{1/sample:\}\ \{answer:\}\ 1/sample:\}\n\ \ \ foreach\ i\ \{1\ 2\ 3\ 4\ 5\ 6\ \}\ \{\n\ \ \ \ label\ .frame.label\$i\ -text\ \[lindex\ \$names\ \$i\]\ -anchor\ e\n\ \ \ \ entry\ .frame.entry\$i\ -width\ 35\ -textvariable\ side\$i\n\ \ \ \ grid\ .frame.label\$i\ .frame.entry\$i\ -sticky\ ew\ -pady\ 2\ -padx\ 1\n\ \ \ \ \ \}\n\ \ proc\ about\ \{\}\ \{\n\ \ \ \ set\ msg\ \"Calculator\ for\ Probablity\ N-sided\ Double\ Dice.\n\ \ \ \ \ \ \ \ \ \ from\ TCL\ WIKI,\n\ \ \ \ \ \ \ \ \ \ written\ on\ eTCL\ \"\n\ \ \ \ \n\ \ \ \ tk_messageBox\ -title\ \"About\"\ -message\ \$msg\n\ \}\n\ \ \ \ \ proc\ pi\ \{\}\ \{expr\ acos(-1)\}\n\n\ \ \ \ \ proc\ fact\ n\ \{expr\ \{\n\ \ \ \ \n\ \ \ \ \ \$n<2?\ 1:\n\ \ \ \ \ \$n>20?\ pow(\$n,\$n)*exp(-\$n)*sqrt(2*acos(-1)*\$n):\n\ \ \ \ \ \ \ \ \ \ \ \ wide(\$n)*\[fact\ \[incr\ n\ -1\]\]\}\n\ \ \ \ \ \}\n\n\ \ \ \ \ \ proc\ listofnn\ \{\ nn\ \}\ \{\n\ \ \ \ \ \ #\ prob.\ subroutines\ for\ two\ 6-sided\ dice\n\ \ \ \ \ \ #\ throw\ of\ 7\ etc.\n\ \ \ \ \ \ \n\ \ \ \ \ \ for\ \{\ set\ i\ 1\ \}\ \{\ \$i\ <=\ \$nn\ \}\ \ \{\ incr\ i\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ lappend\ lister\ \$i\n\ \ \ \ \ \ \}\n\ \ \ \ \ \ set\ i\ 0\n\ \ \ \ \ \ while\ \{\ \[\ incr\ i\ \]\ <=\ \$nn\ \}\ \{\n\ \ \ \ \ \ \ \ \ foreach\ item\ \$lister\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ append\ listofnn\ \"\ \[\ expr\ \{\$item+\$i\}\ \]\"\n\ \ \ \ \ \ \ \ \ \}\n\ \n\ \ \ \ \ \ \}\n\ \ \ \ \ return\ \$listofnn\n\ \ \ \ \ \ \}\n\ \ \ \ \ proc\ dice\ \{\ facen\ nn\ \ \ \}\ \ \{\ \n\ \ \ \ \ #\ prob.\ subroutines\ for\ two\ 6-sided\ dice\n\ \ \ \ \ #\ throw\ of\ 7\ etc.\n\ \ \ \ \ \ \ set\ facen\ \[\ expr\ \{\ int(\$facen)\ \}\ \]\ \n\ \ \ \ \ \ \ set\ nn\ \[\ expr\ \{\ int(\$nn)\ \}\ \]\ \n\ \ \ \ \ set\ ee\ \[llength\ \[\ listofnn\ \$nn\ \]\]\n\ \ \ \ \ \n\ \ \ \ \ set\ kk\ \[\ llength\ \[\ lsearch\ -all\ \[\ listofnn\ \$nn\ \]\ \$facen\ \]\ \]\n\ \ \ \ \ set\ prob\ \[\ expr\ \{\ (\$kk*1.)\ /\ (\$ee*1.)\ \ \}\ \]\n\ \ \ \ \ return\ \$prob\n\ \ \ \ \ \}\n\n\ \ proc\ binom\ \{\ aa\ \ bb\ \ cc\ \ \ \ \}\ \{\n\n\ \ \ \ \ \ #set\ aa\ 6\n\ \ \ \ \ \ #set\ bb\ 4\n\ \ \ \ \ \ #set\ cc\ 2\n\ \ \ \ \ \ \ set\ sidex\ \$cc\n\ \ \ \ \ \ \ set\ aa\ \[\ expr\ \{\ int(\$aa)\ \}\ \]\ \n\ \ \ \ \ \ \ set\ cc\ \[\ expr\ \{\ int(\$bb)\ \}\ \]\ \n\ \ \ \ \ \ \ set\ bb\ \[\ expr\ \{\ (\$aa-\$cc)\ \}\ \]\ \n\ \ \ \ \ \ set\ term1\ \[\ fact\ \$aa\ \]\n\ \ \ \ \ \ set\ term2\ \[\ fact\ \$bb\ \]\n\ \ \ \ \ \ set\ term3\ \[\ fact\ \$cc\ \]\n\n\ \ \ \ \ \ set\ sample\ \[\ expr\ \{\ \$sidex**\$aa\}\ \]\n\ \ \ \ \ \ \n\ \ \ \ \ \ set\ binprob\ \[\ expr\ \{\ (\$term1*1.)/(\$term2*\$term3*\$sample*1.)\ \ \}\ \]\n\n\ \ \ \ \ return\ \ \$binprob\ \ \;\n\n\ \ \ \ \ \}\n\n\ \ \ \ proc\ pol\ \{\ xx1\ yy1\ xx3\ yy3\ xx2\ \ \ \}\ \{\n\ \ \ \ \ return\ \[expr\ \{\ \ (((\$xx2-\$xx1)*(\$yy3-\$yy1))/(\$xx3-\$xx1))+\ \$yy1\ \}\ \]\ \;\}\n\n\ \ \ \ proc\ calculate\ \{\ \ \ \ \ \}\ \{\n\ \ \ \ global\ colorwarning\n\ \ \ \ global\ colorback\n\ \ \ \ global\ answer2\ \ \ answer3\n\ \ \ \ global\ side1\ side2\ side3\ side4\ side5\ side6\ \n\ \ \ \ \ \ \ set\ answer2\ \"\"\n\ \ \ \n\ \ \ set\ side3\ \[\ expr\ \{\ int(\$side3)\ \ \ \ \ \}\ \]\n\ \ \ set\ answer2\ \ \[dice\ \ \$side1\ \$side2\ \ \]\ \n\ \ \ \n\ \ \ set\ side4\ \[\ expr\ \{\ \$side2**\$side3\ \ \ \ \ \}\ \]\n\ \ \ set\ side5\ \[\ expr\ \{\ 1./\ (\$side2**\$side3)\ \ \ \ \ \}\ \]\n\ \ \ set\ side6\ \$answer2\ \ \n\ \ \ \n\ \ \ \ \ \ set\ pi5\ \[pi\]\n\ \ \ if\ \{\$answer2\ >=\ \$pi5\}\ \{\ set\ error5\ \ \ \[expr\ \{100.*\$answer2/\$pi5-100.\}\]\ \ \ \}\n\ \ \ if\ \{\$answer2\ <=\ \$pi5\}\ \{\ set\ error5\ \ \ \[expr\ \{100.*\$pi5/\$answer2-100.\}\]\ \ \ \}\n\ \ \ #\$x\ insert\ 1.0\ \"\ %\ error\ \$error5\ \"\ \n\ \ \ #\$t\ insert\ 1.0\ \"\ %\ error\ \ \$error5\ \"\n\n\ \ \ \ \ \ \}\n\ \ \ \ \ \ proc\ fillup\ \{aa\ bb\ cc\ dd\ ee\ ff\ \}\ \{\n\ \ \ \ \n\ \ \ \ .frame.entry1\ insert\ 0\ \"\$aa\"\n\ \ \ \ .frame.entry2\ insert\ 0\ \"\$bb\"\n\ \ \ \ .frame.entry3\ insert\ 0\ \"\$cc\"\n\ \ \ \ .frame.entry4\ insert\ 0\ \"\$dd\"\n\ \ \ \ .frame.entry5\ insert\ 0\ \"\$ee\"\n\ \ \ \ .frame.entry6\ insert\ 0\ \"\$ff\ \"\n\ \ \ \n\ \ \ \ \ \ \}\n\n\ \ \ \ \ \ proc\ clearx\ \{\}\ \{\n\ \ \ \ foreach\ i\ \{1\ 2\ 3\ 4\ 5\ 6\ \}\ \{\n\ \ \ \ \ \ \ \ .frame.entry\$i\ delete\ 0\ end\n\ \ \ \ \}\n\ \ \ \ \}\n\n\ \ \ proc\ reportx\ \{\}\ \{\ \n\ \ \ console\ show\;\n\ \ \ puts\ \"\n\ \ \ The\ interpolation\ function\ takes\ \n\ \ \ two\ know\ points\ on\ a\ line\ and\n\ \ \ solves\ for\ an\ intermediate\ point.\n\ \ \ The\ points\ are\ xx1,yy1,xx2,yy2\ and\ xx3,?yy3?\n\ \ \ The\ interpolation\ function\ loaded\ as\n\ \ \ proc\ pol.\ User\ should\ be\ able\ \n\ \ \ to\ cut\ and\ paste\ (c&p)\n\ \ \ pol\ 50.\ 1000.\ 200.\ 1200.\ \ 150.\n\ \ \ and\ save\ answer\ (1133.3)\ \ on\ console.\n\ \ \ ********\n\ \ \ The\ binom\ function\ takes\ \n\ \ \ three\ \ quantities.\n\ \ \ The\ input\ order\ of\ the\ 3\ items\n\ \ \ is\ \ N_coins\ heads\ sides.\ \ \n\ \ \ and\ solving\ for\ binomial\ probability.\n\ \ \ eg.\ (c&p)\ binom\ 9\ 2\ 2\ gives\ 0.0703\n\ \ \ *********\n\ \ \ The\ listofnn\ function\ \n\ \ \ returns\ a\ list\ of\ combos\ for\n\ \ \ N_sides\ double\ dice.\n\ \ \ Max\ combo\ should\ be\ twice\ N_sides.\n\ \ \ eg.\ (c&p)\ listofnn\ 6\ gives\ 36\ combos\n\ \ \ ************\n\ \ \ The\ dice\ function\ takes\ \n\ \ \ two\ \ quantities.\n\ \ \ The\ input\ order\ of\ the\ 2\ items\n\ \ \ is\ \ throw\ N_sides.\ \ \n\ \ \ eg.(c&p)\ dice\ 7\ 6\ gives\ 0.166\n\ \ \ \ \"\n\n\ \ \ \ \}\n\n\ \ frame\ .buttons\ -bg\ aquamarine4\n\ \ \ \ \n\ \ \ \ ::ttk::button\ .calculator\ -text\ \"Solve\"\ -command\ \{\ calculate\ \ \ \}\n\n\ \ \ \ ::ttk::button\ .test2\ -text\ \"Testcase1\"\ -command\ \{\ clearx\;fillup\ 7.\ 6.\ 2.\ 36.\ \ .0277\ .166\ \}\n\ \ \ \ ::ttk::button\ .test3\ -text\ \"Testcase2\"\ -command\ \{\ clearx\;fillup\ 3.\ 6.\ 2.\ 36.\ \ .0277\ .0555\ \}\n\ \ \ \ ::ttk::button\ .test4\ -text\ \"Testcase3\"\ -command\ \{\ clearx\;fillup\ 2.\ 6.\ 2.\ 36.\ \ .0277\ .0277\ \}\n\ \ \ \ ::ttk::button\ .clearallx\ -text\ clear\ -command\ \{clearx\ \ \}\n\ \ \ \ ::ttk::button\ .about\ -text\ about\ -command\ about\n\ \ \ \ ::ttk::button\ .cons\ -text\ report\ -command\ \{\ reportx\ \}\n\ \ \ \ ::ttk::button\ .exit\ -text\ exit\ -command\ \{exit\}\n\ \ \ \ pack\ .calculator\ \ -in\ .buttons\ -side\ top\ -padx\ 10\ -pady\ 5\n\ \ \ \ \ \n\ \ \ \ pack\ \ .clearallx\ .cons\ .about\ .exit\ .test4\ .test3\ \ .test2\ \ \ -side\ bottom\ -in\ .buttons\n\ \ \ \ grid\ .frame\ .buttons\ -sticky\ ns\ -pady\ \{0\ 10\}\ \n\ \ \ \ \ .\ configure\ -background\ aquamarine4\ -highlightcolor\ brown\ -relief\ raised\ -border\ 30\n\ \ \ \ bind\ .\ <Motion>\ \{wm\ title\ .\ \"Probablity\ N-sided\ Double\ Dice\ Slot\ Calculator\ Example\ \"\}\n======\n\n----\nThe\ testcase\ 4a\ was\ 3\ dice\ rolling\ all\ ones.\ The\ sample\ size\ was\ 6**3\ or\ 216.\n======\n\ set\ zz\ \[\ expr\ \{\ 6**3\ \}\ \]\n======\nThe\ probability\ of\ getting\ all\ ones\ from\ 3\ dice\ was\ 1/(6**3)\ or\ 0.0046296.\ \ \n======\n\ set\ xx\ \[\ expr\ \{\ 1./(6**3)\ \}\ \]\n======\nprintout\ for\ all\ throws\ of\ 3\ dice.\ set\ tcl_precision\ 17\ was\ not\ used\ here,\ but\ I\ can't\ tell\ much\ difference.\ \n======\ \n\ 1\ 0.0\ \n\ 2\ 0.0\ \n\ 3\ 0.004629629629629629\ \n\ 4\ 0.013888888888888888\ \n\ 5\ 0.027777777777777776\ \n\ 6\ 0.046296296296296294\ \n\ 7\ 0.06944444444444445\ \n\ 8\ 0.09722222222222222\ \n\ 9\ 0.11574074074074074\ \n\ 10\ 0.125\ \n\ 11\ 0.125\ \n\ 12\ 0.11574074074074074\ \n\ 13\ 0.09722222222222222\ \n\ 14\ 0.06944444444444445\ \n\ 15\ 0.046296296296296294\ \n\ 16\ 0.027777777777777776\ \n\ 17\ 0.013888888888888888\ \n\ 18\ 0.004629629629629629\ \n\ #end\n======\nall\ throws\ of\ 4\ dice\nset\ tcl_precision\ 17\ (on)\n======\n\ 1\ 0.0\ \n\ 2\ 0.0\ \n\ 3\ 0.0\ \n\ 4\ 0.0007716049382716049\ \n\ 5\ 0.0030864197530864196\ \n\ 6\ 0.007716049382716049\ \n\ 7\ 0.015432098765432098\ \n\ 8\ 0.027006172839506171\ \n\ 9\ 0.043209876543209874\ \n\ 10\ 0.061728395061728392\ \n\ 11\ 0.080246913580246909\ \n\ 12\ 0.096450617283950615\ \n\ 13\ 0.10802469135802469\ \n\ 14\ 0.11265432098765432\ \n\ 15\ 0.10802469135802469\ \n\ 16\ 0.096450617283950615\ \n\ 17\ 0.080246913580246909\ \n\ 18\ 0.061728395061728392\ \n\ 19\ 0.043209876543209874\ \n\ 20\ 0.027006172839506171\ \n\ 21\ 0.015432098765432098\ \n\ 22\ 0.007716049382716049\ \n\ 23\ 0.0030864197530864196\ \n\ 24\ 0.0007716049382716049\ \n\ end\n======\nThe\ testcase\ 5a\ was\ 5\ dice\ rolling\ all\ sixes.\ The\ sample\ size\ was\ 6**5\ or\ 7776.\n======\n\ set\ zz\ \[\ expr\ \{\ 6**5\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ sixes\ from\ 5\ coins\ was\ 1/(6**5)\ or\ \ 1.28E-4\ \n======\n\ set\ xx\ \[\ expr\ \{\ 1./(6**5)\ \}\ \]\n======\n\n\ ----\n**Comments\ Section**\n\n<<discussion>>\nPlease\ place\ any\ comments\ here,\ Thanks.\n\n\n\n<<categories>>\ Toys\ |\ Example\ |\ Calculator\ |\ Mathematics regexp2} CALL {my render {Binomial Probability Slot Calculator Example} **Binomial\ Probability\ Slot\ Calculator\ Example**\n\nThis\ page\ is\ under\ development.\ Comments\ are\ welcome,\ but\ please\ load\ any\ \ comments\ in\ the\ comments\ section\ \ at\ the\ middle\ of\ the\ page.\ Please\ sign\ your\ user-name\ \ with\ the\ same\ courtesy\ that\ I\ will\ give\ you.\ \ Thanks,\[gold\]\n<<TOC>>\n**Introduction**\n\n----\n\[gold\]\ Here\ is\ some\ starter\ code\ for\ Binomial\ Probability\ Slot\ Calculator\ Example.\ The\ impetus\ for\ this\ calculator\ was\ checking\ some\ iching\ probabilities\ on\ the\ \[Chinese\ Iching\ Random\ Weather\ Predictions\].\ Its\ easy\ enough\ to\ plug\ in\ two\ formulas\ into\ the\ \[Slot_Calculator_Demo\]\ example.\ Most\ of\ the\ checked\ testcases\ involve\ flipping\ two\ sided\ objects\ like\ coins\ or\ popsicle\ sticks.\n\n----\nIn\ planning\ any\ software,\ it\ is\ advisable\ to\ gather\ a\ number\ of\ testcases\ to\ check\ the\ results\ of\ the\ program.\ The\ math\ for\ the\ testcases\ can\ be\ checked\ by\ pasting\ statements\ in\ the\ TCL\ console.\ Also,\ some\ of\ the\ pseudocode\ statements\ were\ checked\ in\ the\ google\ search\ engine\ which\ will\ take\ math\ expressions.\ The\ factorial\ procedure\ used\ below\ was\ posted\ by\ Suchenworth.\ Aside\ from\ the\ TCL\ calculator\ display,\ when\ one\ presses\ the\ report\ button\ on\ the\ calculator,\ one\ will\ have\ console\ show\ access\ \ to\ the\ binomial\ function.\ \[and\ the\ factorial\ (fact)\ function.\]\ \ \ \ \n\n----\nFor\ a\ system\ of\ 2\ sided\ sticks\ or\ coins\ of\ the\ number\ N,\ the\ probability\ of\ getting\ all\ zeros\ or\ ones\ would\ be:\n======\n\ set\ aa\ \[\ expr\ \{\ (1./(2**\$N))\}\ \]\ \;#\ generic\ TCL\ \n======\nFor\ three\ coins,\ the\ formula\ would\ be\ 1/(2**3)\ or\ 1/8.\n======\n\ set\ aa\ \[\ expr\ \{\ (1./(2**3)\}\ \]\ \ \n======\nFor\ six\ coins,\ the\ formula\ would\ be\ \ 1./(2**6)\ or\ 1/64\ \n======\n\ set\ aa\ \[\ expr\ \{\ (1./(2**6)\}\ \]\ \ \n======\nFor\ N\ coins,\ the\ probability\ that\ a\ one\ or\ zero\ \nwould\ show\ up\ on\ one\ of\ N\ coins\ would\ be\n======\n\ set\ aa\ \[\ expr\ \{\ (1.-(1./(2**\$N)))\}\ \]\n======\ \n\n----\n\ \ \ \ \ \ \ \nThe\ testcase\ 1\ was\ 6\ choose\ 2.\ The\ sample\ size\ was\ 2**6\ or\ 64.\n======\n\ set\ gg\ \[\ expr\ \{\ 2**6\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 6\ coins\ was\ 1/(2**6)\ or\ 1/64.\n======\n\ set\ rr\ \[\ expr\ \{\ 1./(2**6)\ \}\ \]\n======\nThe\ answer\ for\ 6\ coins\ choose\ 2\ was\ 0.234\n\n----\n\nThe\ testcase\ 2\ was\ 3\ choose\ 2.\ The\ sample\ size\ was\ 2**3\ or\ 8.\n======\n\ set\ kk\ \[\ expr\ \{\ 2**3\ \}\ \]\n======\nThe\ probability\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 3\ coins\ was\ 1/(2**3)\ or\ 1/8.\n======\n\ set\ jj\ \[\ expr\ \{\ 1./(2**3)\ \}\ \]\n======\nThe\ answer\ for\ 3\ coins\ choose\ 2\ was\ 0.375.\n\n----\ \n\nThe\ testcase\ 3\ was\ 12\ choose\ 2.\ The\ sample\ size\ was\ 2**10\ or\ 4096.\n======\n\ set\ xx\ \[\ expr\ \{\ 2**12\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 12\ coins\ was\ 1/(2**12)\ or\ 1/4096\ or\ \ 2.441E-4\ \n======\n\ set\ vv\ \[\ expr\ \{\ 1./(2**12)\ \}\ \]\n======\nThe\ answer\ for\ 12\ choose\ 2\ was\ 0.01611.\n\n----\n**Session\ from\ console**\n======\n\ \ \ \ 1%\ set\ rr\ \[\ expr\ \{\ 1./(2**12)\ \}\ \]\n\ \ \ \ \ \ 0.000244140625\n\ \ \ \ 2%\ set\ gg\ \[\ expr\ \{\ 2**12\ \}\ \]\n\ \ \ \ 4096\n\ \ \ \ 3%\ set\ rr\ \[\ expr\ \{\ 1./(2**6)\ \}\ \]\n\ \ \ \ 0.015625\n\ \ \ \ 4%\ set\ gg\ \[\ expr\ \{\ 2**6\ \}\ \]\n\ \ \ \ 64\n======\n----\ \n\nThe\ testcase\ 4\ was\ 4\ coins\ choose\ 2.\ The\ sample\ size\ was\ 2**4\ or\ 16.\n======\n\ set\ xx\ \[\ expr\ \{\ 2**4\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails.\ from\ 4\ coins\ was\ 1/(2**4)\ or\ 1/16\ or\ \ .0625\n======\n\ set\ vv\ \[\ expr\ \{\ 1./(2**4)\ \}\ \]\n======\nThe\ answer\ for\ 4\ coins\ choose\ 2\ was\ 0.375.\n\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \nThe\ testcase\ 5\ was\ 9\ coins\ choose\ 2.\ The\ sample\ size\ was\ 2**9\ or\ 512.\n======\n\ set\ xx\ \[\ expr\ \{\ 2**9\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 9\ coins\ was\ 1/(2**9)\ or\ 1/512\ or\ \ .00195\ \n======\n\ set\ vv\ \[\ expr\ \{\ 1./(2**9)\ \}\ \]\n======\nThe\ answer\ for\ 9\ coins\ choose\ 2\ was\ 0.0703\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \n----\n**Console\ session**\ \n======\n\ \ \ \ 1%\ set\ xx\ \[\ expr\ \{\ 2**4\ \}\ \]\n\ \ \ \ 16\n\ \ \ \ 2%\ set\ vv\ \[\ expr\ \{\ 1./(2**4)\ \}\ \]\n\ \ \ \ 0.0625\n\ \ \ \ 3%\ binom\ 4\ 2\ 2\n\ \ \ \ 0.375\n\ \ \ \ 4%\ set\ xx\ \[\ expr\ \{\ 2**9\ \}\ \]\n\ \ \ \ 512\n\ \ \ \ 5%\ set\ vv\ \[\ expr\ \{\ 1./(2**9)\ \}\ \]\n\ \ \ \ 0.001953125\n\ \ \ \ 6%\ binom\ 9\ 2\ 2\n\ \ \ \ 0.07031251\n\ \ \ \ %\ fact\ 9\n\ \ \ \ \ \ 362880\n======\ \ \ \ \ \ \ \ \ \n----\ \ \ \nThe\ testcase\ 6\ was\ 20\ coins\ choose\ 10.\ The\ sample\ size\ was\ 2**20\ or\ 1,048,576.\n======\n\ set\ zz\ \[\ expr\ \{\ 2**20\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 20\ coins\ was\ 1/(2**20)\ or\ 1/1,048,576\ \ or\ 9.536E-7.\ \n======\n\ set\ xx\ \[\ expr\ \{\ 1./(2**20)\ \}\ \]\n======\nThe\ answer\ for\ 20\ coins\ choose\ 10\ was\ 0.1762.\n\n----\n\nThe\ testcase\ 7\ was\ 100\ coins\ choose\ 50.\nThe\ sample\ size\ was\ 2**100\ or\ 1.26765E+30.\ngoogle(2\ **\ 100)\ =\ 1.2676506\ ×\ 10E30\n======\ \n\ \ set\ zz\ \[\ expr\ \{\ 2**100\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ heads\ or\ all\ tails\nfrom\ 20\ coins\ was\ 1/(2**100)\ or\ 1/1.26765E+30\ \ or\ 7.888609E-31\ngoogle(1\ /\ (2\ **\ 100))\ =\ 7.88860905\ ×\ 10-31.\n======\n\ set\ xx\ \[\ expr\ \{\ 1./(2**100)\ \}\ \]\n======\nThe\ answer\ for\ 100\ coins\ choose\ 50\ was\ 0.013843748310702326.\n\n**Console\ session\ \ compared\ to\ stattrek.com**\n======\n\ \ \ \ 2%\ binom\ 100\ 50\ 2\n\ \ \ \ 0.07978845608028655\ \ \ \ \ \ \ \ \ \ \ stattrek(\ 0.0795892373871788\ )\ \ \ \ \ \n\ \ \ \ 3%\ \ binom\ 100\ 60\ 2\n\ \ \ \ 0.010872519679731506\ \ \ \ \ \ \ \ \ \ stattrek(0.010843866711638)\ \ \ \n\ \ \ \ 4%\ binom\ 100\ 70\ 2\n\ \ \ \ 2.3243440318642605e-5\ \ \ \ \ \ \ \ \ stattrek(\ 2.31706905801352E-05\ )\ \ \ \ \ \ \n\ \ \ \ 5%\ binom\ 100\ 80\ 2\ \n\ \ \ \ 4.229044215516387e-10\ \ \ \ \ \ \ \ \ stattrek(\ 4.22816326760158E-10\ )\ \ \ \n\ \ \ \ 6%\ binom\ 100\ 90\ 2\ \ \n\ \ \ \ 1.3656690823232337e-17\ \ \ \ \ \ \ \ stattrek(\ 1.36554263874631E-17)\n\ \ \ \ 7%\ binom\ 100\ 95\ 2\ \ \n\ \ \ \ 5.939398609386625e-23\ \ \ \ \ \ \ \ \ stattrek(\ 5.93913811790451E-23)\n\ \ \ \ 8%\ binom\ 100\ 99\ 2\n\ \ \ \ 7.888675454251962e-29\ \ \ \ \ \ \ \ \ stattrek(7.88860905221012E-29)\ \ \n======\ \ \ \ \ \ \ \ \ \n----\n\nThe\ testcase\ 8\ was\ 120\ coins\ choose\ 50.1.329227E+36.\ The\ sample\ size\ was\ 2**120\ or\ 1.329227E+36.\ google(2\ **\ 120)\ =\ 1.329228\ ×\ 10E36\n======\n\ set\ zz\ \[\ expr\ \{\ 2**120\ \}\ \]\ \n======\nThe\ probability\ of\ getting\ all\ heads\ or\ all\ tails\ from\ 120\ coins\ was\ 1/(2**120)\ or\ 1/\ 1.329227E+36\ or\ 7.5231E-37\ google(1\ /\ (2\ **\ 120))\ =\ 7.52316385\ ×\ 10-37\n======\n\ set\ xx\ \[\ expr\ \{\ 1./(2**120)\ \}\ \]\n======\nThe\ answer\ for\ 120\ coins\ choose\ 50\ was\ 0.013843748310702326,\ omparable\ to\ stattrek(0.0138138412069122).\n======\n\ \ \ \ \ #console\ session\ \n\ \ \ \ \ 12%\ binom\ 120\ 50\ 2\n\ \ \ \ \ 0.013843748310702326\ \ \ \n======\ \ \ \ \ \n----\n**Extra\ Credit**\n\nFor\ a\ system\ of\ one\ die\ with\ kk\ sides\ of\ the\ number\ N\ tosses,\ the\ sample\ size\ would\ be:\n======\n\ set\ aa\ \[\ expr\ \{\ (\$kk**\$N)\}\ \]\ \n======\ \ \nFor\ example,\ a\ 6\ sided\ die\ with\ 2\ tosses\ would\ have\ a\ sample\ size\ of\ 6**2\ or\ 36.\n======\n\ set\ aa\ \[\ expr\ \{\ (\ 6**2\ )\}\ \]\ \n======\nThe\ probability\ of\ two\ dice\ having\ the\ same\ face\ like\ snake\ eyes\ (1:1)\ on\ one\ throw\ \ is\ 1/(sample\ size)\ or\ 1/36.\ \n======\n\ set\ pp\ \[\ expr\ \{\ 1./(6**2)\ \}\ \]\n======\n----\nThe\ following\ sums\ the\ numbers\ on\ two\ faces.\ For\ 2\ dice\ of\ 6\ sides,\ the\ probability\ of\ a\ number\ 7\ coming\ up\ is\ 0.1666.\ In\ pseudocode\ statements,\ the\ probability\ of\ two\ dice\ landing\ with\ sum\ 7\ would\ be\ the\ number\ of\ combinations\ that\ add\ up\ to\ seven\ over\ the\ number\ of\ \ all\ possible\ combinations\ from\ throwing\ 2\ dice.\ Such\ a\ \$list\ can\ generated\ in\ the\ auxillary\ eTCL\ script\ at\ the\ bottom\ of\ page.\ \n======\n\ \ \ prob.\ pseudocode\ \ \ =\ nom\ (\$list)\ /\ denom\ (\ \$list)\ \n\ \ \ prob.\ pseudocode\n\ \ \ =\ llength\ \[lsearch\ -all\ \$list\ 7\ \]\ /\ \[llength\ \$list\ \]\n\ \ \ prob.\ pseudocode\n\ \ \ =\ \[llength\ \[lsearch\ -all\ \$list\ 7\ \]\]\ /\ \[llength\ \$list\ \]\n======\nThis\ would\ find\ our\ probability\ of\ throw\ 7\ on\ a\ one\ time\ basis.\ For\ the\ calculator,\ this\ process\ could\ be\ generalized\ into\ a\ subroutine\ that\ generated\ a\ list\ for\ 2\ to\ N\ sides:\ list(N),\ an\ expected\ dice\ throw\ as\ \$facenumber,\ counted\ the\ number\ of\ throws\ showing\ \$facenumber\ in\ list(N),\ and\ counted\ all\ the\ elements\ in\ the\ list(N).\ \n======\n\ \ prob.\ pseudocode\ \ \ =\ \n\ \ \[llength\ \[lsearch\ -all\ \$list(N)\ \$facenumber\ \]\]\ /\ \[llength\ \$list(N)\ \]\n======\nAlso,\ another\ foreach\ loop\ in\ the\ list\ generator\ could\ probably\ generate\ the\ possible\ throws\ of\ three\ dice.\n----\ \ \n\n**Screenshots\ Section**\n\ \ \n\[http://farm5.static.flickr.com/4100/4826856340_d43cb36805.jpg\]\n\n\[http://farm5.static.flickr.com/4102/4830809174_47303eaa2c.jpg\]\n\n\n\[http://farm5.static.flickr.com/4092/4840912575_32c4402fa5.jpg\]\ \n\[http://farm5.static.flickr.com/4149/4841520100_c94c594994.jpg\]\ \n\n\[http://farm5.static.flickr.com/4092/4840912575_32c4402fa5.jpg\]\n\[http://farm5.static.flickr.com/4149/4841520100_c94c594994.jpg\]\ \n\n\n----\n**Comments\ Section**\nPlease\ place\ any\ comments\ here,\ Thanks.\n\n\[gold\]\ Changes.\n\n\ \n----\n**References**\n\n\ \ \ *\ \[factorial\]\n\ \ \ *\ \[Slot_Calculator_Demo\]\n\ \ \ *\ http://www.knowyourluck.com/coins3u.html\ (currently\ 404)\n\ \ \ *\ http://www.learning.com/pdfs/et/activity-35-cointoss.pdf\n\ \ \ *\ http://stattrek.com/Tables/Binomial.aspx\ Binomial\ Distribution\ Calculator\n\ \ \ *\ \[Sample\ Math\ Programs\]\ modified\ \[PSE\}\ operation\ tables\ to\ generate\ throw\ do-loops\n\ \ \ *\ http://hyperphysics.phy-astr.gsu.edu/hbase/math/dice.html\ Statistics\ of\ Dice\ Throw\ \n\ \ \ *\ http://wizardofodds.com/gambling/dice.html\ Dice\ Probability\ basics\n\ \ \ *\ http://www.cobalt.chem.ucalgary.ca/ziegler/educmat/chm386/rudiment/mathbas/probab.htm\ Probability\n\ \ \ *\ http://gwydir.demon.co.uk/jo/probability/calcinfo.htm\ Calculating\ probabilities\ of\ throwing\ two\ dice\n\n\n\ The\ Math\ Forum,Date:\ 05/16/99\ at\ 16:24:04\n\ From:\ Doctor\ Anthony\n\ Subject:\ Re:\ Probability\ dealing\ with\ combinations\ of\ dice\n\n\ The\ Math\ Forum,Date:\ 12/05/2001\ at\ 00:36:56\n\ From:\ Doctor\ Jeremiah\n\ Subject:\ Re:\ Probability\ of\ dicehttp://wiki.tcl.tk/13243\n\nThrowing\ Two\ Dice\n\n\ \ \ *\ \[throw\ a\ dice\]\n\ \ \ *\ \[Dice\]\n\nGoogle\ Answers\ Probability\ of\ Coin\ Flip.mht\n\ \n2\ Dice\ Rolls\ Probability-Statistics\ -\ Separate.mht\nhttp://mathforum.org/library/drmath/view/56627.html\n\n**appendix\ TCL\ programs**\n***Pretty\ Print\ Version***\ \n\n======\n\ \ \ \ #\ Pretty\ Print\ version\ from\ autoindent\ and\ ased\ editor\n\ \ \ \ #\ written\ on\ Windows\ XP\ on\ eTCL\n\ \ \ \ #\ working\ under\ TCL\ version\ 8.5.6\ and\ eTCL\ 1.0.1\n\ \ \ \ #\ gold\ on\ TCL\ WIKI\ ,\ 21Jul2010\n\ \ package\ require\ Tk\n\ \ \ \ frame\ .frame\ -relief\ flat\ -bg\ aquamarine4\n\ \ \ \ pack\ .frame\ -side\ top\ -fill\ y\ -anchor\ center\n\ \ \ \ \n\ \ \ \ set\ names\ \{\{\}\ N_coins:\ heads:\ \{sides:\}\ \{sample:\}\ \{1/sample:\}\ \{answer:\}\ 1/sample:\}\n\ \ \ \ foreach\ i\ \{1\ 2\ 3\ 4\ 5\ 6\ \}\ \{\n\ \ \ \ \ \ \ \ label\ .frame.label\$i\ -text\ \[lindex\ \$names\ \$i\]\ -anchor\ e\n\ \ \ \ \ \ \ \ entry\ .frame.entry\$i\ -width\ 35\ -textvariable\ side\$i\n\ \ \ \ \ \ \ \ grid\ .frame.label\$i\ .frame.entry\$i\ -sticky\ ew\ -pady\ 2\ -padx\ 1\n\ \ \ \ \}\n\ \ \ \ proc\ about\ \{\}\ \{\n\ \ \ \ \ \ \ \ set\ msg\ \"Calculator\ for\ binomial\ probabliity.\n\ \ \ \ \ \ \ \ from\ TCL\ WIKI,\n\ \ \ \ \ \ \ \ written\ on\ eTCL\ \"\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ tk_messageBox\ -title\ \"About\"\ -message\ \$msg\n\ \ \ \ \}\n\ \ \ \ proc\ pi\ \{\}\ \{expr\ acos(-1)\}\n\ \ \ \ \n\ \ \ \ proc\ fact\ n\ \{expr\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ \ \ \ \ \$n<2?\ 1:\n\ \ \ \ \ \ \ \ \ \ \ \ \$n>20?\ pow(\$n,\$n)*exp(-\$n)*sqrt(2*acos(-1)*\$n):\n\ \ \ \ \ \ \ \ \ \ \ \ wide(\$n)*\[fact\ \[incr\ n\ -1\]\]\}\n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ proc\ binomialprobabilty\ \{\ aa\ \ bb\ \ cc\ dd\ \ ee\ \ \ \}\ \{\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ #set\ aa\ 6\n\ \ \ \ \ \ \ \ #set\ bb\ 4\n\ \ \ \ \ \ \ \ #set\ cc\ 2\n\ \ \ \ \ \ \ \ set\ sidex\ \$cc\n\ \ \ \ \ \ \ \ set\ aa\ \[\ expr\ \{\ int(\$aa)\ \}\ \]\n\ \ \ \ \ \ \ \ set\ cc\ \[\ expr\ \{\ int(\$bb)\ \}\ \]\n\ \ \ \ \ \ \ \ set\ bb\ \[\ expr\ \{\ \$aa-\$cc\ \}\ \]\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ term1\ \[\ fact\ \$aa\ \]\n\ \ \ \ \ \ \ \ set\ term2\ \[\ fact\ \$bb\ \]\n\ \ \ \ \ \ \ \ set\ term3\ \[\ fact\ \$cc\ \]\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ sample\ \[\ expr\ \{\ \$sidex**\$aa\}\ \]\n\ \ \ \ \ \ \ \ set\ binprob\ \[\ expr\ \{\ (\$term1*1.)/(\$term2*\$term3*\$sample*1.)\ \ \}\ \]\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ return\ \ \$binprob\ \ \;\n\ \ \ \ \ \ \ \ \n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ proc\ binom\ \{\ aa\ \ bb\ \ cc\ \ \ \ \}\ \{\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ #set\ aa\ 6\n\ \ \ \ \ \ \ \ #set\ bb\ 4\n\ \ \ \ \ \ \ \ #set\ cc\ 2\n\ \ \ \ \ \ \ \ set\ sidex\ \$cc\n\ \ \ \ \ \ \ \ set\ aa\ \[\ expr\ \{\ int(\$aa)\ \}\ \]\n\ \ \ \ \ \ \ \ set\ cc\ \[\ expr\ \{\ int(\$bb)\ \}\ \]\n\ \ \ \ \ \ \ \ set\ bb\ \[\ expr\ \{\ (\$aa-\$cc)\ \}\ \]\n\ \ \ \ \ \ \ \ set\ term1\ \[\ fact\ \$aa\ \]\n\ \ \ \ \ \ \ \ set\ term2\ \[\ fact\ \$bb\ \]\n\ \ \ \ \ \ \ \ set\ term3\ \[\ fact\ \$cc\ \]\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ sample\ \[\ expr\ \{\ \$sidex**\$aa\}\ \]\n\ \ \ \ \ \ \ \ set\ binprob\ \[\ expr\ \{\ (\$term1*1.)/(\$term2*\$term3*\$sample*1.)\ \ \}\ \]\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ return\ \ \$binprob\ \ \;\n\ \ \ \ \ \ \ \ \n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ proc\ pol\ \{\ xx1\ yy1\ xx3\ yy3\ xx2\ \ \ \}\ \{\n\ \ \ \ \ \ \ \ return\ \[expr\ \{\ \ (((\$xx2-\$xx1)*(\$yy3-\$yy1))/(\$xx3-\$xx1))+\ \$yy1\ \}\ \]\ \;\}\n\ \ \ \ \n\ \ \ \ proc\ calculate\ \{\ \ \ \ \ \}\ \{\n\ \ \ \ \ \ \ \ global\ answer2\ \ \n\ \ \ \ \ \ \ \ global\ side1\ side2\ side3\ side4\ side5\ side6\n\ \ \ \ \ \ \ \ set\ answer2\ \ \[\ binomialprobabilty\ \ \$side1\ \$side2\ \$side3\ \$side4\ \$side5\ \ \]\n\ \ \ \ \ \ \ \ set\ side4\ \[\ expr\ \{\ \$side3**\$side1\ \ \ \ \ \}\ \]\n\ \ \ \ \ \ \ \ set\ side5\ \[\ expr\ \{\ 1./\ (\$side3**\$side1)\ \ \ \ \ \}\ \]\n\ \ \ \ \ \ \ \ set\ side6\ \$answer2\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ set\ pi5\ \[pi\]\n\ \ \ \ \ \ \ \ if\ \{\$answer2\ >=\ \$pi5\}\ \{\ set\ error5\ \ \ \[expr\ \{100.*\$answer2/\$pi5-100.\}\]\ \ \ \}\n\ \ \ \ \ \ \ \ if\ \{\$answer2\ <=\ \$pi5\}\ \{\ set\ error5\ \ \ \[expr\ \{100.*\$pi5/\$answer2-100.\}\]\ \ \ \}\n\ \ \ \ \ \ \ \ #\$x\ insert\ 1.0\ \"\ %\ error\ \$error5\ \"\n\ \ \ \ \ \ \ \ #\$t\ insert\ 1.0\ \"\ %\ error\ \ \$error5\ \"\n\ \ \ \ \ \ \ \ \n\ \ \ \ \}\n\ \ \ \ proc\ fillup\ \{aa\ bb\ cc\ dd\ ee\ ff\ \}\ \{\n\ \ \ \ \ \ \ \ \n\ \ \ \ \ \ \ \ .frame.entry1\ insert\ 0\ \"\$aa\"\n\ \ \ \ \ \ \ \ .frame.entry2\ insert\ 0\ \"\$bb\"\n\ \ \ \ \ \ \ \ .frame.entry3\ insert\ 0\ \"\$cc\"\n\ \ \ \ \ \ \ \ .frame.entry4\ insert\ 0\ \"\$dd\"\n\ \ \ \ \ \ \ \ .frame.entry5\ insert\ 0\ \"\$ee\"\n\ \ \ \ \ \ \ \ .frame.entry6\ insert\ 0\ \"\$ff\ \"\n\ \ \ \ \ \ \ \ \n\ \ \ \ \}\n\ \ \ \ proc\ clearx\ \{\}\ \{\n\ \ \ \ \ \ \ \ foreach\ i\ \{1\ 2\ 3\ 4\ 5\ 6\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ .frame.entry\$i\ delete\ 0\ end\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ proc\ reportx\ \{\}\ \{\n\ \ \ \ \ \ \ \ console\ show\;\n\ \ \ \ \ \ \ \ puts\ \"\n\ \ \ \ \ \ \ \ The\ binom\ function\ takes\n\ \ \ \ \ \ \ \ three\ \ quantities.\n\ \ \ \ \ \ \ \ The\ points\ are\ aa,bb\ ,cc.\n\ \ \ \ \ \ \ \ The\ input\ order\ of\ the\ 3\ items\n\ \ \ \ \ \ \ \ is\ \ N_coins\ heads\ sides\n\ \ \ \ \ \ \ \ and\ solving\ for\ binomial\ probability.\n\ \ \ \ \ \ \ \ eg.\ binom\ 9\ 2\ 2\ gives\ 0.0703\n\ \ \ \ \ \ \ \ \"\n\ \ \ \ \}\n\ \ \ \ \n\ \ \ \ frame\ .buttons\ -bg\ aquamarine4\n\ \ \ \ \n\ \ \ \ ::ttk::button\ .calculator\ -text\ \"Solve\"\ -command\ \{\ calculate\ \ \ \}\n\ \ \ \ \n\ \ \ \ ::ttk::button\ .test2\ -text\ \"Testcase1\"\ -command\ \{\ clearx\;fillup\ 6.\ 2.\ 2.\ 64.\ \ .0156\ .234375\ \}\n\ \ \ \ ::ttk::button\ .test3\ -text\ \"Testcase2\"\ -command\ \{\ clearx\;fillup\ \ 3.\ 2.\ 2.\ 8.\ \ .125\ .375\ \}\n\ \ \ \ ::ttk::button\ .test4\ -text\ \"Testcase3\"\ -command\ \{\ clearx\;fillup\ 12.\ 2.\ 2.\ 4096.\ \ 2.4E-4\ .01611\ \}\n\ \ \ \ ::ttk::button\ .clearallx\ -text\ clear\ -command\ \{clearx\ \ \}\n\ \ \ \ ::ttk::button\ .about\ -text\ about\ -command\ about\n\ \ \ \ ::ttk::button\ .cons\ -text\ report\ -command\ \{\ reportx\ \}\n\ \ \ \ ::ttk::button\ .exit\ -text\ exit\ -command\ \{exit\}\n\ \ \ \ pack\ .calculator\ \ -in\ .buttons\ -side\ top\ -padx\ 10\ -pady\ 5\n\ \ \ \ \n\ \ \ \ pack\ \ .clearallx\ .cons\ .about\ .exit\ .test4\ .test3\ \ .test2\ \ \ -side\ bottom\ -in\ .buttons\n\ \ \ \ grid\ .frame\ .buttons\ -sticky\ ns\ -pady\ \{0\ 10\}\n\ \ \ \ .\ configure\ -background\ aquamarine4\ -highlightcolor\ brown\ -relief\ raised\ -border\ 30\n\ \ \ \ wm\ title\ .\ \"Binomial\ Probablity\ Slot\ Calculator\ Example\ \"\n======\n\n****Auxillary\ programs***\ \n\nHere's\ searching\ through\ a\ list\ of\ thrown\ dice\ combos\nfor\ probability.\ The\ worker\ bee\ is\n======\n\ \[\ lsearch\ -all\ \[\ listofnn\ \$nn\ \]\ \$facen\ \]\n\ \$facen\ is\ the\ sum\ of\ a\ 2-dice\ throw\ like\ 7.\n\ \$nn\ is\ the\ number\ of\ sides,eg\ 6.\n======\nSubroutine\ is\ invoked\ by\ a\ foreach\ procedure\nfor\ probability,\ which\ would\ be\ number\ of\ thrown\ 7's\nover\ all\ possible\ throws.\ Drop\ (-all)\ and\ lose\ all,\nreturning\ only\ one\ position\ of\ \"7\"\ in\ list.\n----\n**Console\ program\ \ for\ two\ 6-sided\ dice**\n======\ \n\ \ \ \ \ \ #\ prob.\ subroutines\ for\ two\ 6-sided\ dice\n\ \ \ \ \ \ #\ throw\ of\ 7\ etc.\n\ \ \ \ \ \ proc\ listofnn\ \{\ nn\ \}\ \{\n\ \ \ \ \ \ set\ lister\ \[list\ \]\n\ \ \ \ \ \ for\ \{\ set\ i\ 1\ \}\ \{\ \$i\ <=\ \$nn\ \}\ \ \{\ incr\ i\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ lappend\ lister\ \$i\n\ \ \ \ \ \ \}\n\ \ \ \ \ \ set\ i\ 0\n\ \ \ \ \ \ while\ \{\ \[\ incr\ i\ \]\ <=\ \$nn\ \}\ \{\n\ \ \ \ \ \ \ \ \ foreach\ item\ \$lister\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ append\ listofnn\ \"\ \[\ expr\ \{\$item+\$i\}\ \]\"\n\ \ \ \ \ \ \ \ \ \}\n\ \n\ \ \ \ \ \ \}\n\ \ \ \ \ return\ \$listofnn\n\ \ \ \ \ \ \}\n\ \ \ \ \ proc\ calculation\ \{\ nn\ \ facen\ \}\ \ \{\ \ \ \n\ \ \ \ \ set\ ee\ \[llength\ \[\ listofnn\ \$nn\ \]\]\n\ \ \ \ \ set\ kk\ \[\ llength\ \[\ lsearch\ -all\ \[\ listofnn\ \$nn\ \]\ \$facen\ \]\ \]\n\ \ \ \ \ set\ prob\ \[\ expr\ \{\ (\$kk*1.)\ /\ \$ee\ \ \}\ \]\n\ \ \ \ \ return\ \$prob\n\ \ \ \ \ \}\n\ \ \ \ console\ show\n\ \ \ \ \ \ \ \ \ \ set\ limit\ 12\n\ \ \ \ \ \ \ \ \ \ for\ \{\ set\ i\ 1\ \}\ \{\ \$i\ <=\ \$limit\ \}\ \ \{\ incr\ i\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ lappend\ listxxx\ \$i\ \n\ \ \ \ \ \ \ \ \ \ lappend\ listxxx\ \[\ calculation\ 6\ \$i\ \]\n\ \ \ \ \ \ \ \ \ \ puts\ \"\ \$i\ \[\ calculation\ 6\ \$i\ \]\ \"\n\ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ puts\ \$listxxx\n======\n\ output\ plotted\ in\ jpg\ above\n\ 1\ 0.0\ \n\ 2\ 0.027777777777777776\ \n\ 3\ 0.05555555555555555\ \n\ 4\ 0.08333333333333333\ \n\ 5\ 0.1111111111111111\ \n\ 6\ 0.1388888888888889\ \n\ 7\ 0.16666666666666666\ \n\ 8\ 0.1388888888888889\ \n\ 9\ 0.1111111111111111\ \n\ 10\ 0.08333333333333333\ \n\ 11\ 0.05555555555555555\ \n\ 12\ 0.027777777777777776\ \n\ \ \ \ #end\n\n\ \ \ \ ------\n======\n\ \ \ \ \ #\ written\ on\ Windowws\ XP\ on\ eTCL\ \n\ \ \ \ \ #\ working\ under\ TCL\ version\ 8.5.6\ and\ eTCL\ 1.0.1\ \n\ \ \ \ \ #\ gold\ on\ TCL\ WIKI\ ,\ 21Jul2010\n\ \ \ \ \ #\ find\ probability\ of\ 7\ on\ 2\ 6-sided\ dice.\n\n\ \ \ \ \ \ proc\ listofnn\ \{\ nn\ \}\ \{\n\ \ \ \ \ \ set\ lister\ \[list\ \]\n\ \ \ \ \ \ for\ \{\ set\ i\ 1\ \}\ \{\ \$i\ <=\ \$nn\ \}\ \ \{\ incr\ i\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ lappend\ lister\ \$i\n\ \ \ \ \ \ \}\n\ \ \ \ \ \ set\ i\ 0\n\ \ \ \ \ \ #puts\ \$lister\n\ \ \ \ \ \ while\ \{\ \[\ incr\ i\ \]\ <=\ \$nn\ \}\ \{\n\ \ \ \ \ \ \ \ \ foreach\ item\ \$lister\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ append\ listofnn\ \"\ \[\ expr\ \{\$item+\$i\}\ \]\"\n\ \ \ \ \ \ \ \ \ \}\n\ \n\ \ \ \ \ \ \}\n\ \ \ \ \ return\ \$listofnn\n\ \}\n\n\ \ \ \ console\ show\n\ \ \ \ #not\ efficient\ code\ here.\n\ \ \ \ #trying\ to\ show\ evolution\n\ \ \ \ #from\ pseudocode\n\ \ \ \ puts\ \"\ prob.\ pseudocode\ \ \ =\ nom\ (\\\$list)\ \\/\ denom\ (\ \\\$list)\ \"\n\n\ \ \ \ puts\ \"pseudocode:find\ all\ possible\ combinations\ from\ throwing\ 2\ dice\"\n\ \ \ \ puts\ \[\ listofnn\ 6\ \]\n\ \ \ \ puts\ \"pseudocode:\ find\ length\ of\ list\"\n\ \ \ \ puts\ \"pseudocode:\\\[llength\ \\\$list\ \\\]\"\n\ \ \ \ puts\ \[llength\ \[\ listofnn\ 6\ \]\]\n\ \ \ \ set\ ee\ \[llength\ \[\ listofnn\ 6\ \]\]\n\ \ \ \ puts\ \"pseudocode:\ find\ positions\ of\ 7\ in\ list\"\n\ \ \ \ puts\ \"prob.\ pseudocode\ \ \ \\=\ \\\[lsearch\ -all\ \\\$list\ 7\ \\\]\ \"\n\n\ \ \ \ puts\ \[\ lsearch\ -all\ \[\ listofnn\ 6\ \]\ 7\ \]\n\ \ \ \ puts\ \"pseudocode:\ count\ number\ of\ throws\ of\ 7\"\n\ \ \ \ puts\ \"\ prob.\ pseudocode\ \ \ \\=\ llength\ \\\[lsearch\ -all\ \\\$list\ 7\ \\\]\ \"\n\n\ \ \ \ puts\ \[\ llength\ \[\ lsearch\ -all\ \[\ listofnn\ 6\ \]\ 7\ \]\ \]\n\ \ \ \ set\ kk\ \[\ llength\ \[\ lsearch\ -all\ \[\ listofnn\ 6\ \]\ 7\ \]\ \]\n\ \ \ \ \ puts\ \"prob.\ pseudocode\ \ \ =\ \\\[llength\ \\\[lsearch\ -all\ \\\$list\ 7\ \\\]\\\]\ \\/\ \\\[llength\ \\\$list\ \\\]\"\n\ \ \ \ #not\ efficient\ code\ here.\n\ \ \ \ #trying\ to\ show\ evolution\n\ \ \ \ #from\ pseudocode\n\n\ \ \ \ set\ prob\ \[\ expr\ \{\ (\$kk*1.)\ /\ \$ee\ \ \}\ \]\n\ \ \ \ puts\ \$prob\n\ \ \ \ #end\ of\ deck\n======\n\ \ \ printed\ output\ of\ deck\n\ \ prob.\ pseudocode\ \ \ =\ nom\ (\$list)\ /\ denom\ (\ \$list)\ \n\ \ pseudocode:find\ all\ possible\ combinations\ from\ throwing\ 2\ dice\n\ \ \ 2\ 3\ 4\ 5\ 6\ 7\ 3\ 4\ 5\ 6\ 7\ 8\ 4\ 5\ 6\ 7\ 8\ 9\ 5\ 6\ 7\ 8\ 9\ 10\ 6\ 7\ 8\ 9\ 10\ 11\ 7\ 8\ 9\ 10\ 11\ 12\n\ \ pseudocode:\ find\ length\ of\ list\n\ \ pseudocode:\[llength\ \$list\ \]\n\ \ 36\n\ \ pseudocode:\ find\ positions\ of\ 7\ in\ list\n\ \ prob.\ pseudocode\ \ \ =\ \[lsearch\ -all\ \$list\ 7\ \]\ \n\ \ 5\ 10\ 15\ 20\ 25\ 30\n\ \ pseudocode:\ count\ number\ of\ throws\ of\ 7\n\ \ prob.\ pseudocode\ \ \ =\ llength\ \[lsearch\ -all\ \$list\ 7\ \]\ \n\ \ 6\n\ \ prob.\ pseudocode\ \ \ =\ \[llength\ \[lsearch\ -all\ \$list\ 7\ \]\]\ /\ \[llength\ \$list\ \]\n\ \ 0.16666666666666666\n======\n\ \ \ \n----\n======\n\ \ \ \ \ #\ written\ on\ Windowws\ XP\ on\ eTCL\ \n\ \ \ \ \ #\ working\ under\ TCL\ version\ 8.5.6\ and\ eTCL\ 1.0.1\ \n\ \ \ \ \ #\ gold\ on\ TCL\ WIKI\ ,\ 21Jul2010\n\ \ \ \ \ frame\ .frame\ -relief\ flat\ -bg\ aquamarine4\n\ \ \ \ \ \ pack\ .frame\ -side\ top\ -fill\ y\ -anchor\ center\n\n\ \ \ \ set\ names\ \{\{\}\ \{throw:\}\ \{N_sides:\}\ \{No_dice:\}\ \{sample:\}\ \{1/sample:\}\ \{answer:\}\ 1/sample:\}\n\ \ \ foreach\ i\ \{1\ 2\ 3\ 4\ 5\ 6\ \}\ \{\n\ \ \ \ label\ .frame.label\$i\ -text\ \[lindex\ \$names\ \$i\]\ -anchor\ e\n\ \ \ \ entry\ .frame.entry\$i\ -width\ 35\ -textvariable\ side\$i\n\ \ \ \ grid\ .frame.label\$i\ .frame.entry\$i\ -sticky\ ew\ -pady\ 2\ -padx\ 1\n\ \ \ \ \ \}\n\ \ proc\ about\ \{\}\ \{\n\ \ \ \ set\ msg\ \"Calculator\ for\ Probablity\ N-sided\ Double\ Dice.\n\ \ \ \ \ \ \ \ \ \ from\ TCL\ WIKI,\n\ \ \ \ \ \ \ \ \ \ written\ on\ eTCL\ \"\n\ \ \ \ \n\ \ \ \ tk_messageBox\ -title\ \"About\"\ -message\ \$msg\n\ \}\n\ \ \ \ \ proc\ pi\ \{\}\ \{expr\ acos(-1)\}\n\n\ \ \ \ \ proc\ fact\ n\ \{expr\ \{\n\ \ \ \ \n\ \ \ \ \ \$n<2?\ 1:\n\ \ \ \ \ \$n>20?\ pow(\$n,\$n)*exp(-\$n)*sqrt(2*acos(-1)*\$n):\n\ \ \ \ \ \ \ \ \ \ \ \ wide(\$n)*\[fact\ \[incr\ n\ -1\]\]\}\n\ \ \ \ \ \}\n\n\ \ \ \ \ \ proc\ listofnn\ \{\ nn\ \}\ \{\n\ \ \ \ \ \ #\ prob.\ subroutines\ for\ two\ 6-sided\ dice\n\ \ \ \ \ \ #\ throw\ of\ 7\ etc.\n\ \ \ \ \ \ \n\ \ \ \ \ \ for\ \{\ set\ i\ 1\ \}\ \{\ \$i\ <=\ \$nn\ \}\ \ \{\ incr\ i\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ lappend\ lister\ \$i\n\ \ \ \ \ \ \}\n\ \ \ \ \ \ set\ i\ 0\n\ \ \ \ \ \ while\ \{\ \[\ incr\ i\ \]\ <=\ \$nn\ \}\ \{\n\ \ \ \ \ \ \ \ \ foreach\ item\ \$lister\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ append\ listofnn\ \"\ \[\ expr\ \{\$item+\$i\}\ \]\"\n\ \ \ \ \ \ \ \ \ \}\n\ \n\ \ \ \ \ \ \}\n\ \ \ \ \ return\ \$listofnn\n\ \ \ \ \ \ \}\n\ \ \ \ \ proc\ dice\ \{\ facen\ nn\ \ \ \}\ \ \{\ \n\ \ \ \ \ #\ prob.\ subroutines\ for\ two\ 6-sided\ dice\n\ \ \ \ \ #\ throw\ of\ 7\ etc.\n\ \ \ \ \ \ \ set\ facen\ \[\ expr\ \{\ int(\$facen)\ \}\ \]\ \n\ \ \ \ \ \ \ set\ nn\ \[\ expr\ \{\ int(\$nn)\ \}\ \]\ \n\ \ \ \ \ set\ ee\ \[llength\ \[\ listofnn\ \$nn\ \]\]\n\ \ \ \ \ \n\ \ \ \ \ set\ kk\ \[\ llength\ \[\ lsearch\ -all\ \[\ listofnn\ \$nn\ \]\ \$facen\ \]\ \]\n\ \ \ \ \ set\ prob\ \[\ expr\ \{\ (\$kk*1.)\ /\ (\$ee*1.)\ \ \}\ \]\n\ \ \ \ \ return\ \$prob\n\ \ \ \ \ \}\n\n\ \ proc\ binom\ \{\ aa\ \ bb\ \ cc\ \ \ \ \}\ \{\n\n\ \ \ \ \ \ #set\ aa\ 6\n\ \ \ \ \ \ #set\ bb\ 4\n\ \ \ \ \ \ #set\ cc\ 2\n\ \ \ \ \ \ \ set\ sidex\ \$cc\n\ \ \ \ \ \ \ set\ aa\ \[\ expr\ \{\ int(\$aa)\ \}\ \]\ \n\ \ \ \ \ \ \ set\ cc\ \[\ expr\ \{\ int(\$bb)\ \}\ \]\ \n\ \ \ \ \ \ \ set\ bb\ \[\ expr\ \{\ (\$aa-\$cc)\ \}\ \]\ \n\ \ \ \ \ \ set\ term1\ \[\ fact\ \$aa\ \]\n\ \ \ \ \ \ set\ term2\ \[\ fact\ \$bb\ \]\n\ \ \ \ \ \ set\ term3\ \[\ fact\ \$cc\ \]\n\n\ \ \ \ \ \ set\ sample\ \[\ expr\ \{\ \$sidex**\$aa\}\ \]\n\ \ \ \ \ \ \n\ \ \ \ \ \ set\ binprob\ \[\ expr\ \{\ (\$term1*1.)/(\$term2*\$term3*\$sample*1.)\ \ \}\ \]\n\n\ \ \ \ \ return\ \ \$binprob\ \ \;\n\n\ \ \ \ \ \}\n\n\ \ \ \ proc\ pol\ \{\ xx1\ yy1\ xx3\ yy3\ xx2\ \ \ \}\ \{\n\ \ \ \ \ return\ \[expr\ \{\ \ (((\$xx2-\$xx1)*(\$yy3-\$yy1))/(\$xx3-\$xx1))+\ \$yy1\ \}\ \]\ \;\}\n\n\ \ \ \ proc\ calculate\ \{\ \ \ \ \ \}\ \{\n\ \ \ \ global\ colorwarning\n\ \ \ \ global\ colorback\n\ \ \ \ global\ answer2\ \ \ answer3\n\ \ \ \ global\ side1\ side2\ side3\ side4\ side5\ side6\ \n\ \ \ \ \ \ \ set\ answer2\ \"\"\n\ \ \ \n\ \ \ set\ side3\ \[\ expr\ \{\ int(\$side3)\ \ \ \ \ \}\ \]\n\ \ \ set\ answer2\ \ \[dice\ \ \$side1\ \$side2\ \ \]\ \n\ \ \ \n\ \ \ set\ side4\ \[\ expr\ \{\ \$side2**\$side3\ \ \ \ \ \}\ \]\n\ \ \ set\ side5\ \[\ expr\ \{\ 1./\ (\$side2**\$side3)\ \ \ \ \ \}\ \]\n\ \ \ set\ side6\ \$answer2\ \ \n\ \ \ \n\ \ \ \ \ \ set\ pi5\ \[pi\]\n\ \ \ if\ \{\$answer2\ >=\ \$pi5\}\ \{\ set\ error5\ \ \ \[expr\ \{100.*\$answer2/\$pi5-100.\}\]\ \ \ \}\n\ \ \ if\ \{\$answer2\ <=\ \$pi5\}\ \{\ set\ error5\ \ \ \[expr\ \{100.*\$pi5/\$answer2-100.\}\]\ \ \ \}\n\ \ \ #\$x\ insert\ 1.0\ \"\ %\ error\ \$error5\ \"\ \n\ \ \ #\$t\ insert\ 1.0\ \"\ %\ error\ \ \$error5\ \"\n\n\ \ \ \ \ \ \}\n\ \ \ \ \ \ proc\ fillup\ \{aa\ bb\ cc\ dd\ ee\ ff\ \}\ \{\n\ \ \ \ \n\ \ \ \ .frame.entry1\ insert\ 0\ \"\$aa\"\n\ \ \ \ .frame.entry2\ insert\ 0\ \"\$bb\"\n\ \ \ \ .frame.entry3\ insert\ 0\ \"\$cc\"\n\ \ \ \ .frame.entry4\ insert\ 0\ \"\$dd\"\n\ \ \ \ .frame.entry5\ insert\ 0\ \"\$ee\"\n\ \ \ \ .frame.entry6\ insert\ 0\ \"\$ff\ \"\n\ \ \ \n\ \ \ \ \ \ \}\n\n\ \ \ \ \ \ proc\ clearx\ \{\}\ \{\n\ \ \ \ foreach\ i\ \{1\ 2\ 3\ 4\ 5\ 6\ \}\ \{\n\ \ \ \ \ \ \ \ .frame.entry\$i\ delete\ 0\ end\n\ \ \ \ \}\n\ \ \ \ \}\n\n\ \ \ proc\ reportx\ \{\}\ \{\ \n\ \ \ console\ show\;\n\ \ \ puts\ \"\n\ \ \ The\ interpolation\ function\ takes\ \n\ \ \ two\ know\ points\ on\ a\ line\ and\n\ \ \ solves\ for\ an\ intermediate\ point.\n\ \ \ The\ points\ are\ xx1,yy1,xx2,yy2\ and\ xx3,?yy3?\n\ \ \ The\ interpolation\ function\ loaded\ as\n\ \ \ proc\ pol.\ User\ should\ be\ able\ \n\ \ \ to\ cut\ and\ paste\ (c&p)\n\ \ \ pol\ 50.\ 1000.\ 200.\ 1200.\ \ 150.\n\ \ \ and\ save\ answer\ (1133.3)\ \ on\ console.\n\ \ \ ********\n\ \ \ The\ binom\ function\ takes\ \n\ \ \ three\ \ quantities.\n\ \ \ The\ input\ order\ of\ the\ 3\ items\n\ \ \ is\ \ N_coins\ heads\ sides.\ \ \n\ \ \ and\ solving\ for\ binomial\ probability.\n\ \ \ eg.\ (c&p)\ binom\ 9\ 2\ 2\ gives\ 0.0703\n\ \ \ *********\n\ \ \ The\ listofnn\ function\ \n\ \ \ returns\ a\ list\ of\ combos\ for\n\ \ \ N_sides\ double\ dice.\n\ \ \ Max\ combo\ should\ be\ twice\ N_sides.\n\ \ \ eg.\ (c&p)\ listofnn\ 6\ gives\ 36\ combos\n\ \ \ ************\n\ \ \ The\ dice\ function\ takes\ \n\ \ \ two\ \ quantities.\n\ \ \ The\ input\ order\ of\ the\ 2\ items\n\ \ \ is\ \ throw\ N_sides.\ \ \n\ \ \ eg.(c&p)\ dice\ 7\ 6\ gives\ 0.166\n\ \ \ \ \"\n\n\ \ \ \ \}\n\n\ \ frame\ .buttons\ -bg\ aquamarine4\n\ \ \ \ \n\ \ \ \ ::ttk::button\ .calculator\ -text\ \"Solve\"\ -command\ \{\ calculate\ \ \ \}\n\n\ \ \ \ ::ttk::button\ .test2\ -text\ \"Testcase1\"\ -command\ \{\ clearx\;fillup\ 7.\ 6.\ 2.\ 36.\ \ .0277\ .166\ \}\n\ \ \ \ ::ttk::button\ .test3\ -text\ \"Testcase2\"\ -command\ \{\ clearx\;fillup\ 3.\ 6.\ 2.\ 36.\ \ .0277\ .0555\ \}\n\ \ \ \ ::ttk::button\ .test4\ -text\ \"Testcase3\"\ -command\ \{\ clearx\;fillup\ 2.\ 6.\ 2.\ 36.\ \ .0277\ .0277\ \}\n\ \ \ \ ::ttk::button\ .clearallx\ -text\ clear\ -command\ \{clearx\ \ \}\n\ \ \ \ ::ttk::button\ .about\ -text\ about\ -command\ about\n\ \ \ \ ::ttk::button\ .cons\ -text\ report\ -command\ \{\ reportx\ \}\n\ \ \ \ ::ttk::button\ .exit\ -text\ exit\ -command\ \{exit\}\n\ \ \ \ pack\ .calculator\ \ -in\ .buttons\ -side\ top\ -padx\ 10\ -pady\ 5\n\ \ \ \ \ \n\ \ \ \ pack\ \ .clearallx\ .cons\ .about\ .exit\ .test4\ .test3\ \ .test2\ \ \ -side\ bottom\ -in\ .buttons\n\ \ \ \ grid\ .frame\ .buttons\ -sticky\ ns\ -pady\ \{0\ 10\}\ \n\ \ \ \ \ .\ configure\ -background\ aquamarine4\ -highlightcolor\ brown\ -relief\ raised\ -border\ 30\n\ \ \ \ bind\ .\ <Motion>\ \{wm\ title\ .\ \"Probablity\ N-sided\ Double\ Dice\ Slot\ Calculator\ Example\ \"\}\n======\n\n----\nThe\ testcase\ 4a\ was\ 3\ dice\ rolling\ all\ ones.\ The\ sample\ size\ was\ 6**3\ or\ 216.\n======\n\ set\ zz\ \[\ expr\ \{\ 6**3\ \}\ \]\n======\nThe\ probability\ of\ getting\ all\ ones\ from\ 3\ dice\ was\ 1/(6**3)\ or\ 0.0046296.\ \ \n======\n\ set\ xx\ \[\ expr\ \{\ 1./(6**3)\ \}\ \]\n======\nprintout\ for\ all\ throws\ of\ 3\ dice.\ set\ tcl_precision\ 17\ was\ not\ used\ here,\ but\ I\ can't\ tell\ much\ difference.\ \n======\ \n\ 1\ 0.0\ \n\ 2\ 0.0\ \n\ 3\ 0.004629629629629629\ \n\ 4\ 0.013888888888888888\ \n\ 5\ 0.027777777777777776\ \n\ 6\ 0.046296296296296294\ \n\ 7\ 0.06944444444444445\ \n\ 8\ 0.09722222222222222\ \n\ 9\ 0.11574074074074074\ \n\ 10\ 0.125\ \n\ 11\ 0.125\ \n\ 12\ 0.11574074074074074\ \n\ 13\ 0.09722222222222222\ \n\ 14\ 0.06944444444444445\ \n\ 15\ 0.046296296296296294\ \n\ 16\ 0.027777777777777776\ \n\ 17\ 0.013888888888888888\ \n\ 18\ 0.004629629629629629\ \n\ #end\n======\nall\ throws\ of\ 4\ dice\nset\ tcl_precision\ 17\ (on)\n======\n\ 1\ 0.0\ \n\ 2\ 0.0\ \n\ 3\ 0.0\ \n\ 4\ 0.0007716049382716049\ \n\ 5\ 0.0030864197530864196\ \n\ 6\ 0.007716049382716049\ \n\ 7\ 0.015432098765432098\ \n\ 8\ 0.027006172839506171\ \n\ 9\ 0.043209876543209874\ \n\ 10\ 0.061728395061728392\ \n\ 11\ 0.080246913580246909\ \n\ 12\ 0.096450617283950615\ \n\ 13\ 0.10802469135802469\ \n\ 14\ 0.11265432098765432\ \n\ 15\ 0.10802469135802469\ \n\ 16\ 0.096450617283950615\ \n\ 17\ 0.080246913580246909\ \n\ 18\ 0.061728395061728392\ \n\ 19\ 0.043209876543209874\ \n\ 20\ 0.027006172839506171\ \n\ 21\ 0.015432098765432098\ \n\ 22\ 0.007716049382716049\ \n\ 23\ 0.0030864197530864196\ \n\ 24\ 0.0007716049382716049\ \n\ end\n======\nThe\ testcase\ 5a\ was\ 5\ dice\ rolling\ all\ sixes.\ The\ sample\ size\ was\ 6**5\ or\ 7776.\n======\n\ set\ zz\ \[\ expr\ \{\ 6**5\ \}\ \]\n======\nThe\ probabliity\ of\ getting\ all\ sixes\ from\ 5\ coins\ was\ 1/(6**5)\ or\ \ 1.28E-4\ \n======\n\ set\ xx\ \[\ expr\ \{\ 1./(6**5)\ \}\ \]\n======\n\n\ ----\n**Comments\ Section**\n\n<<discussion>>\nPlease\ place\ any\ comments\ here,\ Thanks.\n\n\n\n<<categories>>\ Toys\ |\ Example\ |\ Calculator\ |\ Mathematics} CALL {my revision {Binomial Probability Slot Calculator Example}} CALL {::oo::Obj1598205 process revision/Binomial+Probability+Slot+Calculator+Example} CALL {::oo::Obj1598203 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4