home *** CD-ROM | disk | FTP | other *** search
- /* Dice Probability Calculator
- Copyright © 1992 Jason Chahin
-
- This program is free software; you can redistribute it and/or modify it under
- the terms of the GNU General Public License as published by the Free Software
- Foundation, either version 1, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful, but WITHOUT
- ANY WARRANTY; without even the implied warranty of merchantability of FITNESS
- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
- details.
-
- You should have received a copy of the GNU General Public License along with
- this program; if not, write to the Free Software Foundation, Inc., 675
- Massachussetts Ave., Cambridge, MA 02139, USA.
-
- */
- esc= '1b'x
- numeric digits 4
- say esc"[0;3mDice Probability Calculator © Jason Chahin 1992"
- say esc"[0;0m"
- Say "This program will calculate the probability of rolling a number on the first"
- say "try using two dice with N sides (2dN)."
- do forever
- up=0
- number=0
- outcomes=0
- faces=0
- say ""
- say "Give me the number of faces in dice, i.e 8 for 2d8; (from 2-1000):"
- parse pull faces
- do while faces>1000 | faces<=1 | datatype(faces,'w')~=1
- say "Invalid input, try again."
- pull faces
- end
- outcomes=faces**2
- say "Give me the number you wish to roll on your first try (2-"2*faces"):"
- pull number
- do while number<2 | number>2*faces | datatype(number,'w')~=1
- say "Invalid input, try again."
- pull number
- end
- counter=faces
- odds=0
- second=faces
- calc=0
- say "Should I think out loud (y/n)? "
- do until q="Y" | q="N"
- pull q
- if q~="Y" & q~="N" then say "Try again.."
- end
- if q="N" then up=1
- t=time(r)
- do w=1 to faces /* Probability Engine */
- calc=calc+1
- if up~=1 then do
- say ""
- say "Roll Number #"w"/"faces
- end
- do n=1 to counter
- calc=calc+1
- joe=n+second
- if up~=1 then do
- say n "+" second "=" joe
- end
- if n+second=number then do
- calc=calc+1
- odds=odds+1
- if up~=1 then do
- say n "+" second "=" number "<<-----Found combination #"odds
- end
- end
- end
- if second>1 then do
- calc=calc+1
- second=second-1
- end
- end
- timer=time(e)
- say ""
- say "All done."
- say "There are "esc"[33m"outcomes esc"[35mpossible outcomes in 2d"esc"[33m"faces||esc"[35m."
- if odds>1 then
- say "There were "esc"[33m"odds esc"[35moccurences of the number "esc"[33m"number|| esc"[35m."
- else say "There was "esc"[33m"odds esc"[35moccurence of the number " esc"[33m"number esc"[35m."
- say "The odds of rolling a "esc"[33m"number esc"[35mon your first try are "esc"[33m"odds"/"outcomes esc"[35mor "esc"[33m"odds*100/outcomes"%"esc"[35m"
- say "Your computer just completed a total "esc"[33m"calc esc"[35mArexx instructions in "esc"[33m"timer esc"[35mseconds."
- say ""
- say "Continue (y/n)?"
- do until c="Y" | c="N"
- pull c
- if c~="Y" & c~="N" then say "Try again.."
- end
- if c="N" then
- leave
- end
-