Author Topic: Mega sena database  (Read 18828 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mega sena database
« Reply #30 on: April 03, 2019, 11:45:58 pm »
OK I fool proofed the code.

Now it does rewrite the file every day!

Code: QB64: [Select]
  1.  
  2. INPUT "How many millions today "; millions 'day 1 say 1, day 2 say 2...
  3.  
  4. PRINT "Calculating..."
  5. OPEN "temp.txt" FOR OUTPUT AS #1
  6. FOR num1 = 1 TO 55
  7.     LOCATE 5, 3: PRINT num1,
  8.     FOR num2 = num1 + 1 TO 56
  9.         LOCATE 5, 5: PRINT num2,
  10.         FOR num3 = num2 + 1 TO 57
  11.             LOCATE 5, 7: PRINT num3,
  12.             FOR num4 = num3 + 1 TO 58
  13.                 LOCATE 5, 9: PRINT num4,
  14.                 FOR num5 = num4 + 1 TO 59
  15.                     LOCATE 5, 11: PRINT num5,
  16.                     FOR num6 = num5 + 1 TO 60
  17.                         LOCATE 5, 13: PRINT num6
  18.                         s$ = LTRIM$(STR$(num1)) + ","
  19.                         IF num1 < 10 THEN s$ = "0" + s$
  20.                         IF num2 < 10 THEN s$ = s$ + "0"
  21.                         s$ = s$ + LTRIM$(STR$(num2)) + ","
  22.                         IF num3 < 10 THEN s$ = s$ + "0"
  23.                         s$ = s$ + LTRIM$(STR$(num3)) + ","
  24.                         IF num4 < 10 THEN s$ = s$ + "0"
  25.                         s$ = s$ + LTRIM$(STR$(num4)) + ","
  26.                         IF num5 < 10 THEN s$ = s$ + "0"
  27.                         s$ = s$ + LTRIM$(STR$(num5)) + ","
  28.                         IF num6 < 10 THEN s$ = s$ + "0"
  29.                         s$ = s$ + LTRIM$(STR$(num6))
  30.                         count = count + 1
  31.                         IF count < millions * 10 ^ 6 + 1 THEN
  32.                             PRINT #1, s$
  33.                         ELSE
  34.                             CLOSE #1: PRINT "Done :)": END
  35.                         END IF
  36.                     NEXT
  37.                 NEXT
  38.             NEXT
  39.         NEXT
  40.     NEXT
  41. PRINT "Done :)"
  42.  

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Mega sena database
« Reply #31 on: April 03, 2019, 11:53:12 pm »
Easiest fix:

First, look to see if the file exists.  If not, all the loops numbers start at 1.  If it does, read the last set of numbers into the program and continue:

Code: QB64: [Select]
  1. IF _FILEEXISTS(“temp.txt” THEN
  2.     OPEN “temp.txt” FOR INPUT AS #1
  3.     SEEK #1, LOF(1) - 19 ‘records are 19 bytes each, so back up 19 spots
  4.     INPUT #1, num1start
  5.     INPUT #1, num2start
  6.     INPUT #1, num3start
  7.     INPUT #1, num4start
  8.     INPUT #1, num5start
  9.     INPUT #1, num6start
  10.     num6start = num6start + 1
  11.    ‘Those values are all set to 1, 2, 3, 4, 5, 6
  12.  
  13.  
  14. OPEN “temp.txt” FOR APPEND AS #1
  15.  

Now change the loops to start with that start variable value:

FOR num1 = num1start to 55
    FOR num2 = num2start to 56
       .....so on for 3,4,5,6
   

Then after the NEXT statements, reset the start values to their proper value:
                        NEXT num6
                        num6start = num5 + 1
                    NEXT num5
                    num5start = num4 + 1
               NEXT num4
               num4start = num3 + 1
....and so on.


Add an exit condition in the middle loop after the PRINT #1 statement such as:
    IF INKEY$ <> “” THEN END

Then you can build, stop, and resume building that list whenever you want.
     
« Last Edit: April 03, 2019, 11:54:21 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mega sena database
« Reply #32 on: April 05, 2019, 06:36:33 pm »
Good night
Thanks to bplus and Steve for the kindness to create the codes I needed.
Thanks also for taking the time to help. Both codes are working the way I wanted them to.
If Mr. FellippeHeitor does not feel uncomfortable. I wanted to ask for a final help from bplus or Steve.

I want to modify the line: IF INKEY $ <> "" THEN END without the end and without goto.
I want it to continue in Steve's reading code in reply (Reply # 16 from the forum).

Here's the image of bplus and Steve codes working perfectly.

It also follows the only code with the creation of the file and reading for bplus or Steve shows how to redirect the "Esc" to the reading line.

I reiterate the apology to Mr. FellippeHeitor if he feels uncomfortable.

Thanks Bplus and Steve
CarlosCordeiro
 
Bplus Excelente.jpg
 
Bplus Excelente.jpg
Steve Excelente.jpg
* Steve Excelente.jpg (Filesize: 261.33 KB, Dimensions: 1027x1005, Views: 351)
* Único código.txt (Filesize: 2.89 KB, Downloads: 188)
« Last Edit: April 05, 2019, 06:41:00 pm by carloscordeiro »

FellippeHeitor

  • Guest
Re: Mega sena database
« Reply #33 on: April 05, 2019, 11:15:02 pm »
If Mr. FellippeHeitor does not feel uncomfortable. I wanted to ask for a final help from bplus or Steve.
(...)
I reiterate the apology to Mr. FellippeHeitor if he feels uncomfortable.

I imagine this comes from my comment:

Quote
I have nothing to do with this, but why again?

I just asked because I honestly wanted to understand the purpose of the number generation, not because the thread bothered me in any way, shape or form.

Mr. FellippeHeitor just happens to be a forum member with elevated privileges, but this community is something on its own, meaning I have no veto powers whatsoever (nor do I want them). You are welcome and free to discuss your code, request help and get help from others. This is your community too.

All the best,

Fica tranquilo, bicho grilo.

Fellippe.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mega sena database
« Reply #34 on: April 06, 2019, 10:05:20 am »
Quote
Mr. FellippeHeitor
is better than gold!

Easiest fix:

First, look to see if the file exists.  If not, all the loops numbers start at 1.  If it does, read the last set of numbers into the program and continue:

Code: QB64: [Select]
  1. IF _FILEEXISTS(“temp.txt” THEN
  2.     OPEN “temp.txt” FOR INPUT AS #1
  3.     SEEK #1, LOF(1) - 19 ‘records are 19 bytes each, so back up 19 spots
  4.     INPUT #1, num1start
  5.     INPUT #1, num2start
  6.     INPUT #1, num3start
  7.     INPUT #1, num4start
  8.     INPUT #1, num5start
  9.     INPUT #1, num6start
  10.     num6start = num6start + 1
  11.    ‘Those values are all set to 1, 2, 3, 4, 5, 6
  12.  
  13.  
  14. OPEN “temp.txt” FOR APPEND AS #1
  15.  

Now change the loops to start with that start variable value:

FOR num1 = num1start to 55
    FOR num2 = num2start to 56
       .....so on for 3,4,5,6
   

Then after the NEXT statements, reset the start values to their proper value:
                        NEXT num6
                        num6start = num5 + 1
                    NEXT num5
                    num5start = num4 + 1
               NEXT num4
               num4start = num3 + 1
....and so on.


Add an exit condition in the middle loop after the PRINT #1 statement such as:
    IF INKEY$ <> “” THEN END

Then you can build, stop, and resume building that list whenever you want.
     

"Easiest fix"  ?  :-))

Carlos, if I fix this:
Code: QB64: [Select]
  1.  
  2. IF _FILEEXISTS("temp.txt") THEN
  3.     OPEN "temp.txt" FOR INPUT AS #1
  4.     SEEK #1, LOF(1) - 19 'records are 19 bytes each, so back up 19 spots
  5.     INPUT #1, num1start
  6.     INPUT #1, num2start
  7.     INPUT #1, num3start
  8.     INPUT #1, num4start
  9.     INPUT #1, num5start
  10.     INPUT #1, num6start
  11.     num6start = num6start + 1
  12.     'Those values are all set to 1, 2, 3, 4, 5, 6
  13.  
  14.  
  15. PRINT "Calculating..."
  16. OPEN "temp.txt" FOR APPEND AS #1
  17. FOR num1 = num1start TO 55
  18.     LOCATE 5, 3: PRINT num1,
  19.     FOR num2 = num2start TO 56
  20.         LOCATE 5, 7: PRINT num2,
  21.         FOR num3 = num3start TO 57
  22.             LOCATE 5, 11: PRINT num3,
  23.             FOR num4 = num4start TO 58
  24.                 LOCATE 5, 15: PRINT num4,
  25.                 FOR num5 = num5start TO 59
  26.                     LOCATE 5, 19: PRINT num5,
  27.                     FOR num6 = num6start TO 60
  28.                         LOCATE 5, 21: PRINT num6
  29.                         s$ = LTRIM$(STR$(num1)) + ","
  30.                         IF num1 < 10 THEN s$ = "0" + s$
  31.                         IF num2 < 10 THEN s$ = s$ + "0"
  32.                         s$ = s$ + LTRIM$(STR$(num2)) + ","
  33.                         IF num3 < 10 THEN s$ = s$ + "0"
  34.                         s$ = s$ + LTRIM$(STR$(num3)) + ","
  35.                         IF num4 < 10 THEN s$ = s$ + "0"
  36.                         s$ = s$ + LTRIM$(STR$(num4)) + ","
  37.                         IF num5 < 10 THEN s$ = s$ + "0"
  38.                         s$ = s$ + LTRIM$(STR$(num5)) + ","
  39.                         IF num6 < 10 THEN s$ = s$ + "0"
  40.                         s$ = s$ + LTRIM$(STR$(num6))
  41.                         PRINT #1, s$
  42.                         IF INKEY$ <> "" THEN END
  43.                     NEXT
  44.                     num6start = num5 + 1
  45.                 NEXT
  46.                 num5start = num4 + 1
  47.             NEXT
  48.             num4start = num3 + 1
  49.         NEXT
  50.         num3start = num2 + 1
  51.     NEXT
  52.     num2start = num1 + 1
  53.  
  54.  
  55.  
  56.  
  57.  
  58. OPEN "temp.txt" FOR INPUT AS #1
  59. 'Apenas listar todos os numeros / combinacoeses
  60. FOR recordnumber = 1 TO 50063830
  61.     SEEK #1, (recordnumber - 1) * 19 + 1
  62.     LINE INPUT #1, t$
  63.     PRINT "Registro"; recordnumber; ":"; t$
  64.     IF INKEY$ <> "" THEN EXIT FOR 'Esc para sair...
  65.  
  66. 'Para obter um valor especifico da lista:
  67.  
  68.  
  69.     PRINT
  70.     PRINT
  71.     DO
  72.         INPUT "Digite um Numero de 1 a 50063830:"; recordnumber
  73.         IF recordnumber = 0 GOTO OutsideLoop
  74.     LOOP UNTIL recordnumber > 0 AND recordnumber < 50063831
  75.     SEEK #1, (recordnumber - 1) * 19 + 1
  76.     LINE INPUT #1, t$
  77.     PRINT "Resgistro"; recordnumber; ":"; t$
  78.  
  79. 'Gerando aleatoriamente valores usando nossa lista:
  80. OutsideLoop:
  81. FOR i = 1 TO 10
  82.     recordnumber = INT(RND * 50063830) + 1
  83.     SEEK #1, (recordnumber - 1) * 19 + 1
  84.     LINE INPUT #1, t$
  85.     PRINT "Random Drawing #"; i; ": "; t$
  86.  
  87.  

and if it helps you win the jackpot, you will remember me right? ;-))

and the person who helps me help you by translating the comments to the code blocks, so I know what it is exactly the code is trying to accomplish, remember that person too.
« Last Edit: April 06, 2019, 10:09:52 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mega sena database
« Reply #35 on: April 06, 2019, 12:58:20 pm »
Holy ship! Steve's Append Method is a disaster, it does not end like this:
 
error Carlos #3 Steve's Append Method NOT THIS!.PNG


Going back to fool proof method!
« Last Edit: April 06, 2019, 01:37:50 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mega sena database
« Reply #36 on: April 06, 2019, 02:14:31 pm »
Fixed!
Code: QB64: [Select]
  1. 'remove Steve's Append Method, replace with B+ Fool Proofed Method
  2.  
  3. CONST maxRecord = 50063860 'number of combs of numbers 1 to 60 tkaen 6 at a time
  4.  
  5. PRINT "Enter how many lines you want in the file up to"; maxRecord;: INPUT " ", recsDesired
  6. IF recsDesired < 1 THEN END ' don't know what is what
  7. IF recsDesired > maxRecord THEN
  8.     PRINT "Only"; maxRecord; " records allowed, will use that!"
  9.     recsDesired = maxRecord
  10.     PRINT "press any to continue..."
  11.     SLEEP
  12.     PRINT
  13. PRINT "Calculating records..."
  14. OPEN "temp.txt" FOR OUTPUT AS #1 ' Fool Proof Method: rewrite file to recsDesired
  15. IF recs < recsDesired THEN 'rewrite the file
  16.     FOR num1 = 1 TO 55
  17.         LOCATE 5, 3: PRINT num1,
  18.         FOR num2 = num1 + 1 TO 56
  19.             LOCATE 5, 5: PRINT num2,
  20.             FOR num3 = num2 + 1 TO 57
  21.                 LOCATE 5, 7: PRINT num3,
  22.                 FOR num4 = num3 + 1 TO 58
  23.                     LOCATE 5, 9: PRINT num4,
  24.                     FOR num5 = num4 + 1 TO 59
  25.                         LOCATE 5, 11: PRINT num5,
  26.                         FOR num6 = num5 + 1 TO 60
  27.                             LOCATE 5, 13: PRINT num6
  28.                             s$ = LTRIM$(STR$(num1)) + ","
  29.                             IF num1 < 10 THEN s$ = "0" + s$
  30.                             IF num2 < 10 THEN s$ = s$ + "0"
  31.                             s$ = s$ + LTRIM$(STR$(num2)) + ","
  32.                             IF num3 < 10 THEN s$ = s$ + "0"
  33.                             s$ = s$ + LTRIM$(STR$(num3)) + ","
  34.                             IF num4 < 10 THEN s$ = s$ + "0"
  35.                             s$ = s$ + LTRIM$(STR$(num4)) + ","
  36.                             IF num5 < 10 THEN s$ = s$ + "0"
  37.                             s$ = s$ + LTRIM$(STR$(num5)) + ","
  38.                             IF num6 < 10 THEN s$ = s$ + "0"
  39.                             s$ = s$ + LTRIM$(STR$(num6))
  40.                             count = count + 1
  41.                             IF count <= recsDesired THEN
  42.                                 PRINT #1, s$
  43.                             ELSE
  44.                                 GOTO skipOut
  45.                             END IF
  46.                         NEXT
  47.                     NEXT
  48.                 NEXT
  49.             NEXT
  50.         NEXT
  51.     NEXT
  52. skipOut:
  53.  
  54. ' What really should happen is to write the data file once with something like the above code
  55. ' and then access the file whenever with the code below.
  56.  
  57. OPEN "temp.txt" FOR INPUT AS #1
  58. nRecords = LOF(1) / 19
  59.  
  60. 'Apenas listar todos os numeros / combinacoeses >>> List all combinations, yuck too many!
  61. ' show last 10 listings
  62. PRINT: PRINT "Here is the last 10 lines of file:"
  63. FOR recordnumber = nRecords - 10 TO nRecords
  64.     SEEK #1, (recordnumber - 1) * 19 + 1
  65.     LINE INPUT #1, t$
  66.     PRINT "Registro"; recordnumber; ":"; t$
  67. PRINT: INPUT "Press enter to continue..."; wate$
  68.  
  69.  
  70. 'Para obter um valor especifico da list  >>> to get a specific value from the list, why?  eh... OK
  71.     'Carlos, you can not access record 50063860 unless you have that many in file
  72.     PRINT: PRINT "(Enter 0 to quit, Digite um Numero de 1 a"; nRecords; " of current file:";
  73.     INPUT " "; recordnumber
  74.     IF recordnumber < 1 THEN EXIT DO
  75.     IF recordnumber <= nRecords THEN
  76.         SEEK #1, (recordnumber - 1) * 19 + 1
  77.         LINE INPUT #1, t$
  78.         PRINT "Resgistro"; recordnumber; ":"; t$
  79.     ELSE
  80.         BEEP
  81.     END IF
  82.  
  83. 'Gerando aleatoriamente valores usando nossa lista  >>> Randomly Generating values using our list:
  84. PRINT "10 Random lines from file with"; nRecords; "records in it."
  85. FOR i = 1 TO 10
  86.     'Carlos, can only access records up to number in file NOT 50063860
  87.     recordnumber = INT(RND * nRecords) + 1
  88.     'recordnumber = 63074 'check one known record OK
  89.     SEEK #1, (recordnumber - 1) * 19 + 1
  90.     LINE INPUT #1, t$
  91.     PRINT "Random Drawing #"; i; ": "; t$
  92. PRINT: PRINT "All done, goodbye!"
  93.  
  94.  

But the mystery continues, why rewrite the data file?
« Last Edit: April 06, 2019, 02:18:08 pm by bplus »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Mega sena database
« Reply #37 on: April 06, 2019, 05:11:52 pm »
Holy ship! Steve's Append Method is a disaster, it does not end like this:
 
error Carlos #3 Steve's Append Method NOT THIS!.PNG


Going back to fool proof method!

Not a disaster; just off with a very tiny bit of file logic:

Code: QB64: [Select]
  1. IF _FILEEXISTS("temp.txt") THEN
  2.     OPEN "temp.txt" FOR INPUT AS #1
  3.     SEEK #1, LOF(1) - 17 'records are 19 bytes each, but last line won't have a CRLF, so back up 17 spots instead of 19
  4.     INPUT #1, num1start
  5.     INPUT #1, num2start
  6.     INPUT #1, num3start
  7.     INPUT #1, num4start
  8.     INPUT #1, num5start
  9.     INPUT #1, num6start
  10.     num6start = num6start + 1
  11.     PRINT "Resuming count from old file."
  12.     num1start = 1
  13.     num2start = 2
  14.     num3start = 3
  15.     num4start = 4
  16.     num5start = 5
  17.     num6start = 6
  18.  
  19.  
  20. PRINT "Calculating further values..."
  21. PRINT "Press <ANY KEY> to stop."
  22. OPEN "temp.txt" FOR APPEND AS #1
  23.  
  24.  
  25.  
  26.  
  27.  
  28. FOR num1 = num1start TO 55
  29.     LOCATE 5, 1: PRINT num1,
  30.     FOR num2 = num2start TO 56
  31.         LOCATE 6, 1: PRINT num2,
  32.         FOR num3 = num3start TO 57
  33.             LOCATE 7, 1: PRINT num3,
  34.             FOR num4 = num4start TO 58
  35.                 LOCATE 8, 1: PRINT num4,
  36.                 FOR num5 = num5start TO 59
  37.                     LOCATE 9, 1: PRINT num5,
  38.                     FOR num6 = num6start TO 60
  39.                         LOCATE 10, 1: PRINT num6
  40.                         s$ = LTRIM$(STR$(num1)) + ","
  41.                         IF num1 < 10 THEN s$ = "0" + s$
  42.                         IF num2 < 10 THEN s$ = s$ + "0"
  43.                         s$ = s$ + LTRIM$(STR$(num2)) + ","
  44.                         IF num3 < 10 THEN s$ = s$ + "0"
  45.                         s$ = s$ + LTRIM$(STR$(num3)) + ","
  46.                         IF num4 < 10 THEN s$ = s$ + "0"
  47.                         s$ = s$ + LTRIM$(STR$(num4)) + ","
  48.                         IF num5 < 10 THEN s$ = s$ + "0"
  49.                         s$ = s$ + LTRIM$(STR$(num5)) + ","
  50.                         IF num6 < 10 THEN s$ = s$ + "0"
  51.                         s$ = s$ + LTRIM$(STR$(num6))
  52.                         PRINT #1, s$
  53.                         IF INKEY$ <> "" THEN PRINT: PRINT: PRINT "Terminated Program.  Calculation paused; run it again to resume list generation.": END
  54.                     NEXT
  55.                     num6start = num5start + 1
  56.                 NEXT
  57.                 num5start = num4start + 1
  58.             NEXT
  59.             num4start = num3start + 1
  60.         NEXT
  61.         num3start = num2start + 1
  62.     NEXT
  63.     num2start = num1start + 1
  64.  

The above works as intended and allows you to stop and resume list generation however you want.  The change necessary for the example I posted to work was this simple:

Change this:
Code: QB64: [Select]
  1. IF _FILEEXISTS(“temp.txt” THEN
  2.     OPEN “temp.txt” FOR INPUT AS #1
  3.     SEEK #1, LOF(1) - 19 ‘records are 19 bytes each, so back up 19 spots

To:
Code: QB64: [Select]
  1. IF _FILEEXISTS("temp.txt") THEN
  2.     OPEN "temp.txt" FOR INPUT AS #1
  3.     SEEK #1, LOF(1) - 17 'records are 19 bytes each, but last line won't have a CRLF, so back up 17 spots instead of 19

I would've thought all the lines in the program would have a CRLF set at the end of them, but that doesn't hold true for the last record in the list.  It simply ends, so we back up 17 spots instead of 19 to get the proper values for us.  An easy thing to overlook without actually running and testing the code, but it seems to fix the issue for me,  (Unless further testing shows another glitch somewhere that I just haven't found yet, which is always possible...)

https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mega sena database
« Reply #38 on: April 06, 2019, 05:24:57 pm »
Hello bplus
Good night
Should I win the prize? Of course I will remember you bplus. You and Steve deserve it, for dedicating yourself to a newcomer like me. Just send the account number. :)
I am not trying to rewrite the data file.
I was trying to put in the only code, the two codes that you and Steve created for me.
The code that generates the combinations and the code that read the combinations.
In a single code, the two codes together into one.
With a Loop, more with the IF INKEY $ <> "" THEN END in the end for when I want to leave.
 I ran the latter and it made a mistake on the line that is Seek
CarlosCordeiro
Line 71.jpg
* Line 71.jpg (Filesize: 329.29 KB, Dimensions: 1317x1005, Views: 302)

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mega sena database
« Reply #39 on: April 06, 2019, 05:32:26 pm »
I had not read Steve's post yet, I'm going to test it now

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Mega sena database
« Reply #40 on: April 06, 2019, 05:48:50 pm »
Slight correction to remove some duplicate values from our list generation.  It's a little bit trickier than I first imagined, but I think this does it properly for us:

Code: QB64: [Select]
  1. IF _FILEEXISTS("temp.txt") THEN
  2.     OPEN "temp.txt" FOR INPUT AS #1
  3.     SEEK #1, LOF(1) - 17 'records are 19 bytes each, but last line won't have a CRLF, so back up 17 spots instead of 19
  4.     INPUT #1, num1start
  5.     INPUT #1, num2start
  6.     INPUT #1, num3start
  7.     INPUT #1, num4start
  8.     INPUT #1, num5start
  9.     INPUT #1, num6start
  10.     num6start = num6start + 1
  11.     PRINT "Resuming count from old file."
  12.     num1start = 1
  13.     num2start = 2
  14.     num3start = 3
  15.     num4start = 4
  16.     num5start = 5
  17.     num6start = 6
  18.     PRINT "Generating values in new 'temp.txt' file."
  19.  
  20.  
  21. PRINT "Calculating further values..."
  22. PRINT "Press <ANY KEY> to stop."
  23. OPEN "temp.txt" FOR APPEND AS #1
  24.  
  25.  
  26.  
  27.  
  28.  
  29. FOR num1 = num1start TO 55
  30.     LOCATE 5, 1: PRINT num1,
  31.     IF num1 = num2start THEN num2start = num2start + 1
  32.     FOR num2 = num2start TO 56
  33.         LOCATE 6, 1: PRINT num2,
  34.         IF num2 = num3start THEN num3start = num3start + 1
  35.         FOR num3 = num3start TO 57
  36.             LOCATE 7, 1: PRINT num3,
  37.             IF num3 = num4start THEN num4start = num4start + 1
  38.             FOR num4 = num4start TO 58
  39.                 LOCATE 8, 1: PRINT num4,
  40.                 IF num4 = num5start THEN num5start = num5start + 1
  41.                 FOR num5 = num5start TO 59
  42.                     LOCATE 9, 1: PRINT num5,
  43.                     IF num5 = num6start THEN num6start = num6start + 1
  44.                     FOR num6 = num6start TO 60
  45.                         LOCATE 10, 1: PRINT num6
  46.                         s$ = LTRIM$(STR$(num1)) + ","
  47.                         IF num1 < 10 THEN s$ = "0" + s$
  48.                         IF num2 < 10 THEN s$ = s$ + "0"
  49.                         s$ = s$ + LTRIM$(STR$(num2)) + ","
  50.                         IF num3 < 10 THEN s$ = s$ + "0"
  51.                         s$ = s$ + LTRIM$(STR$(num3)) + ","
  52.                         IF num4 < 10 THEN s$ = s$ + "0"
  53.                         s$ = s$ + LTRIM$(STR$(num4)) + ","
  54.                         IF num5 < 10 THEN s$ = s$ + "0"
  55.                         s$ = s$ + LTRIM$(STR$(num5)) + ","
  56.                         IF num6 < 10 THEN s$ = s$ + "0"
  57.                         s$ = s$ + LTRIM$(STR$(num6))
  58.                         PRINT #1, s$
  59.                         IF INKEY$ <> "" THEN PRINT: PRINT: PRINT "Terminated Program.  Calculation paused; run it again to resume list generation.": END
  60.                     NEXT
  61.                     num6start = num5 + 1
  62.                 NEXT
  63.                 num5start = num4 + 1
  64.             NEXT
  65.             num4start = num3 + 1
  66.         NEXT
  67.         num3start = num2 + 1
  68.     NEXT
  69.     num2start = num1 + 1
  70.  
  71.  
« Last Edit: April 06, 2019, 05:49:56 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mega sena database
« Reply #41 on: April 06, 2019, 08:45:06 pm »
Slight correction to remove some duplicate values from our list generation.  It's a little bit trickier than I first imagined, but I think this does it properly for us:

Code: QB64: [Select]
  1. IF _FILEEXISTS("temp.txt") THEN
  2.     OPEN "temp.txt" FOR INPUT AS #1
  3.     SEEK #1, LOF(1) - 17 'records are 19 bytes each, but last line won't have a CRLF, so back up 17 spots instead of 19
  4.     INPUT #1, num1start
  5.     INPUT #1, num2start
  6.     INPUT #1, num3start
  7.     INPUT #1, num4start
  8.     INPUT #1, num5start
  9.     INPUT #1, num6start
  10.     num6start = num6start + 1
  11.     PRINT "Resuming count from old file."
  12.     num1start = 1
  13.     num2start = 2
  14.     num3start = 3
  15.     num4start = 4
  16.     num5start = 5
  17.     num6start = 6
  18.     PRINT "Generating values in new 'temp.txt' file."
  19.  
  20.  
  21. PRINT "Calculating further values..."
  22. PRINT "Press <ANY KEY> to stop."
  23. OPEN "temp.txt" FOR APPEND AS #1
  24.  
  25.  
  26.  
  27.  
  28.  
  29. FOR num1 = num1start TO 55
  30.     LOCATE 5, 1: PRINT num1,
  31.     IF num1 = num2start THEN num2start = num2start + 1
  32.     FOR num2 = num2start TO 56
  33.         LOCATE 6, 1: PRINT num2,
  34.         IF num2 = num3start THEN num3start = num3start + 1
  35.         FOR num3 = num3start TO 57
  36.             LOCATE 7, 1: PRINT num3,
  37.             IF num3 = num4start THEN num4start = num4start + 1
  38.             FOR num4 = num4start TO 58
  39.                 LOCATE 8, 1: PRINT num4,
  40.                 IF num4 = num5start THEN num5start = num5start + 1
  41.                 FOR num5 = num5start TO 59
  42.                     LOCATE 9, 1: PRINT num5,
  43.                     IF num5 = num6start THEN num6start = num6start + 1
  44.                     FOR num6 = num6start TO 60
  45.                         LOCATE 10, 1: PRINT num6
  46.                         s$ = LTRIM$(STR$(num1)) + ","
  47.                         IF num1 < 10 THEN s$ = "0" + s$
  48.                         IF num2 < 10 THEN s$ = s$ + "0"
  49.                         s$ = s$ + LTRIM$(STR$(num2)) + ","
  50.                         IF num3 < 10 THEN s$ = s$ + "0"
  51.                         s$ = s$ + LTRIM$(STR$(num3)) + ","
  52.                         IF num4 < 10 THEN s$ = s$ + "0"
  53.                         s$ = s$ + LTRIM$(STR$(num4)) + ","
  54.                         IF num5 < 10 THEN s$ = s$ + "0"
  55.                         s$ = s$ + LTRIM$(STR$(num5)) + ","
  56.                         IF num6 < 10 THEN s$ = s$ + "0"
  57.                         s$ = s$ + LTRIM$(STR$(num6))
  58.                         PRINT #1, s$
  59.                         IF INKEY$ <> "" THEN PRINT: PRINT: PRINT "Terminated Program.  Calculation paused; run it again to resume list generation.": END
  60.                     NEXT
  61.                     num6start = num5 + 1
  62.                 NEXT
  63.                 num5start = num4 + 1
  64.             NEXT
  65.             num4start = num3 + 1
  66.         NEXT
  67.         num3start = num2 + 1
  68.     NEXT
  69.     num2start = num1 + 1
  70.  
  71.  

Ran your code uninterrupted and it seems to be ending correctly but the record numbers are way, way off!
There should be 50,063,860 combinations, this shows less than 34 millions.
 
steves latest.PNG


Note: my last 10 lines shown above include 0 combinations starting at 52, you have 4.

The way I count, missing by 15 million is a disaster.
« Last Edit: April 06, 2019, 09:03:27 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Mega sena database
« Reply #42 on: April 06, 2019, 09:00:58 pm »
Hello bplus
Good night
Should I win the prize? Of course I will remember you bplus. You and Steve deserve it, for dedicating yourself to a newcomer like me. Just send the account number. :)
I am not trying to rewrite the data file.
I was trying to put in the only code, the two codes that you and Steve created for me.
The code that generates the combinations and the code that read the combinations.
In a single code, the two codes together into one.
With a Loop, more with the IF INKEY $ <> "" THEN END in the end for when I want to leave.
 I ran the latter and it made a mistake on the line that is Seek
CarlosCordeiro

Yes having code that reads the file you just made is fine! But you can not skip making the file first before trying to read it. :-))

Your snapshot shows the last line to be the first record. If you input only 1 line in at the beginning, that is only 1 combination you had the code make. To show last 10 lines, you need to enter at least 10, at the beginning of program. It is no longer doing millions but exactly how many lines you want.
 
Enter number of lines.PNG


You are right, you never said anything about rewriting file. I slipped into that thinking having so much trouble working with Steve's Append method.

Steve, It is a valiant and intriguing attempt, it was not easy to go back to fool proof which apparently was not fool proof enough. ;-))

Good luck to us, Carlos! :)
« Last Edit: April 06, 2019, 09:10:48 pm by bplus »

Offline carloscordeiro

  • Forum Regular
  • Posts: 102
    • View Profile
Re: Mega sena database
« Reply #43 on: April 06, 2019, 11:11:33 pm »
Really bplus, there's a little flaw in Steve's last code, but I think he'll be fixing it.

Another question I have, is it possible to put a line with some command to show the number of combinations registered in the temp.txt file?
For example:
If I want to add in a variable A = numbers of combinations registered in temp.txt.
How to create this line?
Regardless of having reached the end of the 50 million
It seems like I'm asking too much. Oo
Falha.jpg
* Falha.jpg (Filesize: 347.19 KB, Dimensions: 1055x1005, Views: 284)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Mega sena database
« Reply #44 on: April 06, 2019, 11:37:28 pm »
Really bplus, there's a little flaw in Steve's last code, but I think he'll be fixing it.

Another question I have, is it possible to put a line with some command to show the number of combinations registered in the temp.txt file?

One more shot at this -- I was overthinking my process on loading the values and getting things glitched with complexity.  Let's see if this doesn't do what it's supposed to, and what you asked for it to do with the number of combinations written:

Code: QB64: [Select]
  1. DIM RecordOn AS LONG
  2. IF _FILEEXISTS("temp.txt") THEN
  3.     OPEN "temp.txt" FOR INPUT AS #1
  4.     SEEK #1, LOF(1) - 17 'records are 19 bytes each, but last line won't have a CRLF, so back up 17 spots instead of 19
  5.     RecordOn = LOF(1) \ 19 + 1
  6.     INPUT #1, num1start
  7.     INPUT #1, num2start
  8.     INPUT #1, num3start
  9.     INPUT #1, num4start
  10.     INPUT #1, num5start
  11.     INPUT #1, num6start
  12.     num6start = num6start + 1
  13.     PRINT "Resuming count from old file."
  14.     loaded = -1
  15.     CLOSE
  16.     OPEN "temp.txt" FOR APPEND AS #1
  17.     OPEN "temp.txt" FOR OUTPUT AS #1
  18.  
  19.  
  20.  
  21. PRINT "Calculating further values..."
  22. PRINT "Press <ANY KEY> to stop."
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29. FOR num1 = 1 TO 55
  30.     IF loaded THEN num1 = num1start
  31.  
  32.     FOR num2 = num1 + 1 TO 56
  33.         IF loaded THEN num2 = num2start
  34.  
  35.         FOR num3 = num2 + 1 TO 57
  36.             IF loaded THEN num3 = num3start
  37.  
  38.             FOR num4 = num3 + 1 TO 58
  39.                 IF loaded THEN num4 = num4start
  40.  
  41.                 FOR num5 = num4 + 1 TO 59
  42.                     IF loaded THEN num5 = num5start
  43.  
  44.                     FOR num6 = num5 + 1 TO 60
  45.                         RecordOn = RecordOn + 1
  46.                         IF loaded THEN num6 = num6start: loaded = 0
  47.                         s$ = LTRIM$(STR$(num1)) + ","
  48.                         IF num1 < 10 THEN s$ = "0" + s$
  49.                         IF num2 < 10 THEN s$ = s$ + "0"
  50.                         s$ = s$ + LTRIM$(STR$(num2)) + ","
  51.                         IF num3 < 10 THEN s$ = s$ + "0"
  52.                         s$ = s$ + LTRIM$(STR$(num3)) + ","
  53.                         IF num4 < 10 THEN s$ = s$ + "0"
  54.                         s$ = s$ + LTRIM$(STR$(num4)) + ","
  55.                         IF num5 < 10 THEN s$ = s$ + "0"
  56.                         s$ = s$ + LTRIM$(STR$(num5)) + ","
  57.                         IF num6 < 10 THEN s$ = s$ + "0"
  58.                         s$ = s$ + LTRIM$(STR$(num6))
  59.                         LOCATE 5, 1: PRINT "Writing Record"; RecordOn; "of 50,063,860 combinations: "; s$
  60.                         PRINT #1, s$
  61.                         IF INKEY$ <> "" THEN PRINT: PRINT: PRINT "Terminated Program.  Calculation paused; run it again to resume list generation.": END
  62.                     NEXT
  63.                 NEXT
  64.             NEXT
  65.         NEXT
  66.     NEXT
  67.  
« Last Edit: April 06, 2019, 11:39:43 pm by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!