Hi all
Here is some code that is ready to go for anyone interested in the lexie to set RNG. Sorry for the block
format but when I try to paste code from firefox it gets all messed up. I figured some might want to
play around with the code or study how it works. If you have QB64 already installed then just copy the
code between the two lines and paste it into a blank page in the QB64 editor and hit [RUN] plus the option
you want, [Start], [Start detached] or [Make EXE only]
The QB64 editor/compiler can be downloaded at http://www.qb64.net/
I perfer the older SDL version
Note!
The below code is just a simple cNr or combinations calculator. The extra code is needed because some
calculations are returned with a decimal value. The extra code rounds up to 10 digits right of the decimal
to the nearest value. If running a smaller matrix then these lines could be removed. As it is now it is set
for a pick 13 of 99 matrix but these can be set to cover any lesser matrix. This is true of each occurrence
within the code.
NCR = Factorial(NSET) / (Factorial(PICKT) * Factorial(NSET-PICKT)):
NCR$ = LTRIM$(STR$(NCR))
DP1=0
IF INSTR(NCR$, ".") > 0 THEN DP1=CINT(VAL(MID$(NCR$,INSTR(NCR$, "."), 10)))
IF INSTR(NCR$, ".") > 0 THEN NCR$=MID$(NCR$,1,(INSTR(NCR$, ".")-1))
NCR=VAL(NCR$) + DP1
__________________________________________________________________________________________________
DIM SHARED PICKT AS INTEGER
DIM SHARED NSET AS INTEGER
DIM SHARED NCR AS DOUBLE
DIM SHARED NC1 AS DOUBLE
DIM SHARED LEX1 AS DOUBLE
DIM SHARED LEXHI AS DOUBLE
DIM SHARED DP1 AS INTEGER
DIM SHARED L1 AS INTEGER
'I have tested the lexie converter up to 13 lexie digits, However in test it seems to handle a 13 - 99 matrix but
'has not been tested to this level. A 13-99 matrix would have 6,186,171,974,825,304 sets and 16 lexie digits.
'The next two variables below are the matrix values' The converter is limited to a pick-13 of 99 so don't go above these or
'you will get errors
'Pickt can be set from 2 to 13.
PICKT = 13 'numbers in each set
NSET = 99 'total numbers in pool
COUNT=0
time1$=time$
'calculate total combinations in matrix
NCR = Factorial(NSET) / (Factorial(PICKT) * Factorial(NSET-PICKT)):
NCR$ = LTRIM$(STR$(NCR))
DP1=0
IF INSTR(NCR$, ".") > 0 THEN DP1=CINT(VAL(MID$(NCR$,INSTR(NCR$, "."), 10)))
IF INSTR(NCR$, ".") > 0 THEN NCR$=MID$(NCR$,1,(INSTR(NCR$, ".")-1))
NCR=VAL(NCR$) + DP1
locate 2, 2: PRINT "Press any key to stop RNG"
NEXTPAIR:
COUNT=COUNT+1
'stop code, exit on key press
IF INKEY$ <> "" THEN GOTO ENDSIM
'RNG
LEX1=INT(RND*NCR)+1:
'clear/set variables
QP1$="":SET1$="":L1=NSET:LEXHI=(NCR-LEX1):PICK1=PICKT
NEXTCALC:
'calculate combinatons remaining
NC1 = Factorial(L1)/(Factorial(PICK1)*Factorial(L1-PICK1)):
NC1$ = LTRIM$(STR$(NC1)):DP1=0
IF INSTR(NC1$,".") > 0 THEN DP1=CINT(VAL(MID$(NC1$,INSTR(NC1$, "."), 10)))
IF INSTR(NC1$,".") > 0 THEN NC1$=MID$(NC1$,1,(INSTR(NC1$,".")-1))
NC1=VAL(NC1$)+DP1
'main algorithm conversion code
DO UNTIL NC1 <= LEXHI
L1=L1-1:IF L1 <= (PICK1-1) THEN EXIT DO
NC1 = Factorial(L1)/(Factorial(PICK1)*Factorial(L1-PICK1)):
NC1$ = LTRIM$(STR$(NC1))
DP1=0
IF INSTR(NC1$, ".") > 0 THEN DP1=CINT(VAL(MID$(NC1$,INSTR(NC1$, "."), 10)))
IF INSTR(NC1$, ".") > 0 THEN NC1$=MID$(NC1$,1,(INSTR(NC1$, ".")-1))
NC1=VAL(NC1$) + DP1
LOOP
'pad single digits with a zero
IF (NSET - L1) < 10 THEN SET1$=SET1$+"0"+LTRIM$(STR$(NSET-L1))+" "
IF (NSET - L1) > 9 THEN SET1$=SET1$+LTRIM$(STR$(NSET-L1))+" "
'check to see if conversion complete
LEXHI=LEXHI-NC1: PICK1=PICK1-1
IF PICK1 > 0 THEN GOTO NEXTCALC
QP1$=SET1$
'print quickpick set to screen, comment out to increase speed of the program
locate 1,2: PRINT ""; QP1$; ""
GOTO NEXTPAIR 'start over
ENDSIM:
cls
locate 1, 2: print "Total sets generated ->"; count; ""
locate 2, 2: print "Start time ->"; time1$; ""
locate 3, 2: print "End time ->"; time$
locate 4, 2: PRINT "Press any key to exit"
sleep
system
'This function is needed to factor numbers greater than 30
FUNCTION Factorial# (n AS DOUBLE)
CONST maxNToCache = 99
STATIC resultCache() AS DOUBLE
STATIC FIRSTCALL AS INTEGER
IF firstCall = 0 THEN
firstCall = -1
REDIM resultCache(maxNToCache) AS DOUBLE
resultCache(0) = 1
resultCache(1) = 1
resultCache(2) = 2
END IF
IF n <= maxNToCache THEN
IF resultCache(n) <> 0 THEN
Factorial = resultCache(n)
EXIT FUNCTION
END IF
END IF
resultCache(n) = INT(n) * Factorial(INT(n) - 1)
Factorial = resultCache(n)
END FUNCTION
________________________________________________________________________________________________________
Have fun
RL