home *** CD-ROM | disk | FTP | other *** search
- * ****************************************************************
- * Goofy program to calculate combinations.
- * Written by Rod Potter (email rodp@orion.yorku.ca)
- * and foisted on an unsuspecting public.
- ******************************************************************
-
- CLEAR
- SET STATUS OFF
- SET SCOREBOARD OFF
- SET COLO TO /W
- @ 01,00 SAY SPACE(80)
- @ 01,23 SAY " If I had a million dollars... "
- SET COLO TO W/
-
- DO WHILE .T.
- STORE 0 TO NUM,UNIVERSE,NUM2DRAW,M_ANSWER
- @ 08,08 CLEAR TO 15,72
- @ 08,08 TO 15,72
- @ 10,13 SAY "Size of pool to draw from (1-125) " GET UNIVERSE PICT "##########" RANGE 1,125
- @ 11,13 SAY " Size of group (1-125) " GET NUM2DRAW PICT "##########" RANGE 1,125
- READ
- DO CASE
- CASE NUM2DRAW = UNIVERSE
- @ 13,13 SAY "Great odds! Only 1 combination!"
- CASE NUM2DRAW > UNIVERSE
- OK=" "
- @ 23,00 TO 23,79
- @ 24,00 SAY SPACE(80)
- @ 24,00 SAY " Size of group must be smaller than the Pool... Try again." GET OK
- READ
- @ 23,00 CLEAR
- CASE UNIVERSE=0 .or. NUM2DRAW=0
- ** Try again **
- OTHER
- STORE FACT(UNIVERSE) / ( FACT(NUM2DRAW) * FACT(UNIVERSE-NUM2DRAW) ) TO M_ANSWER
- @ 13,13 SAY "The Number of combinations is " + LTRIM(STR(INT(M_ANSWER)))
- ENDCASE
- OK=" "
- @ 23,00 TO 23,79
- @ 24,00 SAY SPACE(80)
- @ 24,00 SAY " Try your luck again? (y/n) " GET OK
- READ
- @ 23,00 CLEAR
- IF .not. OK$"yY"
- CLEAR
- EXIT
- ENDIF
- ENDDO
-
- FUNCTION FACT
- PARAMETER NUM
- STORE NUM TO ANSWER
- FOR NUM = NUM-1 TO 1 STEP - 1
- ANSWER = ANSWER*NUM
- NEXT
- RETURN ANSWER
-
-