home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / RMS05A2.LHA / ReXXmAsHeRv0.5a / Examples / Dice.rexx next >
Encoding:
OS/2 REXX Batch file  |  1980-01-03  |  3.1 KB  |  97 lines

  1. /*                       Dice Probability Calculator
  2.                         Copyright © 1992 Jason Chahin
  3.  
  4. This  program is free software; you can redistribute it and/or modify it under
  5. the  terms of the GNU General Public License as published by the Free Software
  6. Foundation, either version 1, or (at your option) any later version.
  7.  
  8. This  program  is  distributed in the hope that it will be useful, but WITHOUT
  9. ANY  WARRANTY; without even the implied warranty of merchantability of FITNESS
  10. FOR  A  PARTICULAR  PURPOSE.   See  the  GNU  General  Public License for more
  11. details.
  12.  
  13. You  should  have received a copy of the GNU General Public License along with
  14. this  program;  if  not,  write  to  the  Free  Software Foundation, Inc., 675
  15. Massachussetts Ave., Cambridge, MA 02139, USA.
  16.  
  17. */
  18. esc= '1b'x
  19. numeric digits 4
  20. say esc"[0;3m Dice Probability Calculator © Jason Chahin 1992"
  21. say esc"[0;0m"
  22. Say "This program will calculate the probability of rolling a number on the first"
  23. say "try using two dice with N sides (2dN)."
  24. do forever
  25.   up=0
  26.   number=0
  27.   outcomes=0
  28.   faces=0
  29.   say ""
  30.   say "Give me the number of faces in dice, i.e 8 for 2d8; (from 2-1000):"
  31.   parse pull faces
  32.   do while faces>1000 | faces<=1 | datatype(faces,'w')~=1
  33.     say "Invalid input, try again."
  34.     pull faces
  35.   end
  36.   outcomes=faces**2
  37.   say "Give me the number you wish to roll on your first try (2-"2*faces"):"
  38.   pull number
  39.   do while number<2 | number>2*faces | datatype(number,'w')~=1
  40.     say "Invalid input, try again."
  41.     pull number
  42.   end
  43.   counter=faces
  44.   odds=0
  45.   second=faces
  46.   calc=0
  47.   say "Should I think out loud (y/n)? "
  48.   do until q="Y" | q="N"
  49.     pull q
  50.     if q~="Y" & q~="N" then say "Try again.."
  51.   end
  52.   if q="N" then up=1
  53.   t=time(r)
  54.     do w=1 to faces                          /* Probability Engine */
  55.       calc=calc+1
  56.       if up~=1 then do
  57.         say ""
  58.         say "Roll Number #"w"/"faces
  59.       end
  60.       do n=1 to counter
  61.         calc=calc+1
  62.         joe=n+second
  63.         if up~=1 then do
  64.           say n "+" second "=" joe
  65.         end
  66.         if n+second=number then do
  67.           calc=calc+1
  68.           odds=odds+1
  69.             if up~=1 then do
  70.               say n "+" second "=" number "<<-----Found combination #"odds
  71.             end
  72.         end
  73.       end
  74.       if second>1 then do
  75.         calc=calc+1
  76.         second=second-1
  77.       end
  78.     end
  79.   timer=time(e)
  80.   say ""
  81.   say "All done."
  82.   say "There are "esc"[33m"outcomes esc"[35mpossible outcomes in 2d"esc"[33m"faces||esc"[35m."
  83.   if odds>1 then
  84.     say "There were "esc"[33m"odds esc"[35moccurences of the number "esc"[33m"number|| esc"[35m."
  85.    else say "There was "esc"[33m"odds esc"[35moccurence of the number " esc"[33m"number esc"[35m."
  86.   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"
  87.   say "Your computer just completed a total "esc"[33m"calc esc"[35mArexx instructions in "esc"[33m"timer esc"[35mseconds."
  88.   say ""
  89.   say "Continue (y/n)?"
  90.   do until c="Y" | c="N"
  91.     pull c
  92.       if c~="Y" & c~="N" then say "Try again.."
  93.   end
  94.   if c="N" then
  95.     leave
  96. end
  97.