|
Post by bplus on May 30, 2024 12:47:54 GMT
_Title "lotto for carlos" ' b+ 2024-05-30 Randomize Timer Width 80, 40 ' <<< 30 so can fit 25 rows on screen 0 Dim a$(1 To 3) a$(1) = "02 03 05 06 09 10 11 13 14 16 18 20 23 24 25" a$(2) = "01 04 05 06 07 09 11 12 13 15 16 19 20 23 24" a$(3) = "01 04 06 07 08 09 10 11 12 14 16 17 20 23 24" Locate 4 Print CountDigits$(a$(), 25) Print " press any for TicketMaker Demo of 7 tickets of 3 numbers from 1 to 100..." Sleep Cls Dim As Long n, numbers, i, top n = 7: numbers = 3: top = 100 Dim tickets$(1 To n) Print n; " tickets,"; numbers; " numbers from 1 to"; top; ":" For i = 1 To n tickets$(i) = TicketMaker$(numbers, top) Print i, tickets$(i) Next Print: Print "Number Counts:" Print CountDigits$(tickets$(), top) Print: Print " press any to input your own specs for a multiple ticket purchase..." Sleep Cls Print Print " Multiple tickets purchase:" Input "Limit 25 for space Please enter Top number limit "; top Input "Limit 10 for space Please enter number of numbers on a ticket "; numbers Input "Limit 5 for space Please enter number of tickets to purchase "; n Cls If top > 25 Then top = 25 If numbers > 10 Then numbers = 10 If n > 5 Then n = 5 Dim lotto$(1 To n) Print: Print n; " tickets,"; numbers; " numbers from 1 to"; top; ":" For i = 1 To n lotto$(i) = TicketMaker$(numbers, top) Print i, lotto$(i) Next Print: Print "Number Counts:" Print CountDigits$(lotto$(), top)
Function CountDigits$ (digits$(), highest As Long) Dim As Long i, j, num, count(1 To highest) ' variables to process digits strings
Dim rtn$ ' <<< prepare to set function to return this string when done
For i = LBound(digits$) To UBound(digits$) ' count the whole array of digit strings For j = 1 To Len(digits$(i)) Step 3 ' one digit string break down to 3 digit parts num = Val(Mid$(digits$(i), j, 3)) ' convert string to number count(num) = count(num) + 1 ' add to count of that number Next Next For i = 1 To highest ' if not 0, lines of counts put into one l o n g string If count(i) Then rtn$ = rtn$ + S2$(i) + " = " + TS2$(count(i)) + Chr$(10) End If Next CountDigits$ = rtn$ ' <<< returns 25 rows of print in one string End Function
Function TicketMaker$ (number As Long, highest As Long) ' number = number of 2 digit numbers you want ' lowest number allowed is always 1 ' highest number allowed
' because no repeats digits, number can not exceed highest
' please return the numbers sorted from low to high
'example: ' dim a$(1 to 3) ' for i = 1 to 3 ' a$(i) = TicketMaker$(15, 25) ' next ' returns: 'a$(1) = "02 03 05 06 09 10 11 13 14 16 18 20 23 24 25" 'a$(2) = "01 04 05 06 07 09 11 12 13 15 16 19 20 23 24" 'a$(3) = "01 04 06 07 08 09 10 11 12 14 16 17 20 23 24"
Dim As Long shuffle(1 To highest), sort(1 To number), i Dim rtn$
For i = 1 To highest shuffle(i) = i Next For i = highest To 2 Step -1 Swap shuffle(i), shuffle(Int(Rnd * i) + 1) Next For i = 1 To number sort(i) = shuffle(i) Next QuickSort 1, number, sort() For i = 1 To number If Len(rtn$) Then rtn$ = rtn$ + " " + S2$(sort(i)) Else rtn$ = S2$(sort(i)) Next TicketMaker$ = rtn$ End Function
Sub QuickSort (start As Long, finish As Long, array() As Long) Dim Hi As Long, Lo As Long, Middle As Long Hi = finish: Lo = start Middle = array((Lo + Hi) / 2) 'find middle of array Do Do While array(Lo) < Middle: Lo = Lo + 1: Loop Do While array(Hi) > Middle: Hi = Hi - 1: Loop If Lo <= Hi Then Swap array(Lo), array(Hi) Lo = Lo + 1: Hi = Hi - 1 End If Loop Until Lo > Hi If Hi > start Then Call QuickSort(start, Hi, array()) If Lo < finish Then Call QuickSort(Lo, finish, array()) End Sub
Function TS$ (n As Long) ' Trim String for Long Type but integers should work as well TS$ = _Trim$(Str$(n)) End Function
Function TS2$ (n As Long) ' Trim String for Long Type but integers should work as well TS2$ = Right$(" " + TS$(n), 2) End Function
Function S2$ (n As Long) S2$ = Right$("00" + TS$(n), 2) End Function
![](//storage.proboards.com/7292714/thumbnailer/irrUwigVUcPvaslvwGDd.png) ![](//storage.proboards.com/7292714/thumbnailer/vrfVhWdZqMgUIoshQvdm.png)
|
|
|
lotto
May 30, 2024 20:00:17 GMT
Post by carlos45 on May 30, 2024 20:00:17 GMT
Bplus, my friend, I save every code example you fix or make for me. But I didn't understand this example. Does he create hunches? I'll keep this one too.
Carlos
|
|
|
Post by bplus on May 30, 2024 23:53:17 GMT
it not only counts digits in lotto groups of tickets, it makes a lotto ticket with ticketmaker, tell it the numner of numbers to draw and the highest number in the lotto
say the lotto picks 5 numbers with 100 as the top most number possible ticketmaker picks 5 fro 1 to 100 and prints up a ticket.
countDigits has been generalized to handle an array of tickets() given the highest number for that lotto 25, 50... 100
|
|
|
lotto
Jun 3, 2024 22:31:37 GMT
Post by carlos45 on Jun 3, 2024 22:31:37 GMT
Bplus, I ran your example lotto code several times and none of them were the numbers repeated. In a simple way and with a few lines, explain to me how you did it so that there were no repetitions. I think I'm using an obsolete approach. My obsolete approach: Randomize Timer For j = 1 To 15 Do found = False temp = Int(Rnd * 25) + 1 For er = 1 To 15 If NUMEROS(er) = TS2$(temp) Then found = True: Exit For Next er Loop While found NUMEROS(j) = TS2$(temp) Next j
Function TS2$ (nn As Long) TS2$ = Right$("00" + LTrim$(Str$(nn)), 2) End Function
|
|
|
Post by bplus on Jun 4, 2024 1:13:36 GMT
_Title "Drawing numbers without repetitions" 'b+ 2024-06-03
DefLng A-Z ' all variables are long Randomize Timer
highest = 50 ' draw numbers from 1 to 50 drawNumber = 10 ' how many numbers to draw
restart: ReDim deckOfNumbers(1 To highest) ' long also
' load the deck with numbers For i = 1 To highest deckOfNumbers(i) = i ' so the deck so far is very orderly Next
' here is Fisher - Yates shuffle routine the most efficient known to mathematicians For i = highest To 2 Step -1 Swap deckOfNumbers(i), deckOfNumbers(Int(Rnd * i) + 1) ' swap i with 1 to i Next
' now the deck is shuffled !!! check it out For i = 1 To drawNumber Print deckOfNumbers(i); Next Print
' now maybe we want to list numbers in order ReDim order(1 To highest) For i = 1 To drawNumber order(deckOfNumbers(i)) = 1 ' mark the numbers in order Next For i = 1 To highest If order(i) Then Print i; Next Print Print "... that should show:"; drawNumber; "numbers between 1 and"; highest; ", in order, no repeats." Print: Print Input " Please enter Highest number "; highest Input " Please enter Draw number "; drawNumber If highest <> 0 And drawNumber < highest Then GoTo restart
|
|
|
Post by bplus on Jun 4, 2024 8:17:54 GMT
Bplus, I ran your example lotto code several times and none of them were the numbers repeated. In a simple way and with a few lines, explain to me how you did it so that there were no repetitions. I think I'm using an obsolete approach. My obsolete approach: Randomize Timer For j = 1 To 15 Do found = False temp = Int(Rnd * 25) + 1 For er = 1 To 15 If NUMEROS(er) = TS2$(temp) Then found = True: Exit For Next er Loop While found NUMEROS(j) = TS2$(temp) Next j
Function TS2$ (nn As Long) TS2$ = Right$("00" + LTrim$(Str$(nn)), 2) End Function Carlos maybe trying for this: Randomize Timer For times = 1 To 20 ' do this 20 times ReDim NUMEROS(1 To 25) ' reset all to zero For j = 1 To 15 tryAgain: temp = Int(Rnd * 25) + 1 ' random from 1 to 25 inclusive If NUMEROS(temp) Then GoTo tryAgain Else NUMEROS(temp) = 1 ' if already have try again for this time Next For i = 1 To 25 ' see what we got in order If NUMEROS(i) Then Print i; Next Print Next
|
|
|
lotto
Jun 4, 2024 23:25:01 GMT
Post by carlos45 on Jun 4, 2024 23:25:01 GMT
Bplus, This shuffling approach is perfect, I really liked this way of keeping the numbers in order. This code is perfect; I will no longer use my obsolete lines. I created this last line to better understand how he manages to keep it in order. Thank you, Bplus Carlos Attachments:![](//storage.proboards.com/7292714/thumbnailer/iUQoMn0OktWvUjztiXvW.png)
|
|