Number generator comapred to number list
Number generator comapred to number list
(OP)
Hello there
I am writing a program to generate 39 combinations of numbers into rows of 5 each. I managed to do this with the FOR ...NEXT function. I also have a list of numbers I want to compare it to.These are 600 lines of numbers with 5 numbers on each line.If a generated number matches 5 numbers in a line in the database,it will ignore this and GOTO the next generated number until an unmatched number does not come up,in this case it prints to the screen and is counted The problem is this database of numbers is too big to be added to the program code with the DATA and READ statements,so I have to store the date base in a different file and open it to read from it. I have a problem with the program reading the file using the IF ,Then functions and the AND OR functions to compare the data it does not seem to be working.
Here's how the code looks like:
FOR a = 1 TO 35
FOR b = 2 TO 36
FOR c = 3 TO 37
FOR d = 4 TO 38
FOR e = 5 to 39
IF a = b OR a > b THEN 493
IF b = c OR b > c THEN 492
IF c = d OR c > d THEN 491
IF d = e OR 8d > e THEN 490
OPEN "list.txt" FOR INPUT AS #1
DO UNTIL EOF(1)
INPUT #1, aa,bb,cc,dd,ee
IF (aa = a) AND (bb = b) AND (cc = c) AND (dd = d) AND (ee = e) THEN GOTO 299
GOTO 300
299 EXIT DO
CLOSE #1
GOTO 489
300 LOOP
CLOSE #1
301
tot = tot + 1
print a;b;c;d;e
489 NEXT t
490 NEXT e
491 NEXT d
492 NEXT c
493 NEXT b
494 NEXT a
What am I doing wrong?
Is there a better way to write the program?
Is there a way to get past the out of memory issue with Qbasic?
Ta
Mick
I am writing a program to generate 39 combinations of numbers into rows of 5 each. I managed to do this with the FOR ...NEXT function. I also have a list of numbers I want to compare it to.These are 600 lines of numbers with 5 numbers on each line.If a generated number matches 5 numbers in a line in the database,it will ignore this and GOTO the next generated number until an unmatched number does not come up,in this case it prints to the screen and is counted The problem is this database of numbers is too big to be added to the program code with the DATA and READ statements,so I have to store the date base in a different file and open it to read from it. I have a problem with the program reading the file using the IF ,Then functions and the AND OR functions to compare the data it does not seem to be working.
Here's how the code looks like:
FOR a = 1 TO 35
FOR b = 2 TO 36
FOR c = 3 TO 37
FOR d = 4 TO 38
FOR e = 5 to 39
IF a = b OR a > b THEN 493
IF b = c OR b > c THEN 492
IF c = d OR c > d THEN 491
IF d = e OR 8d > e THEN 490
OPEN "list.txt" FOR INPUT AS #1
DO UNTIL EOF(1)
INPUT #1, aa,bb,cc,dd,ee
IF (aa = a) AND (bb = b) AND (cc = c) AND (dd = d) AND (ee = e) THEN GOTO 299
GOTO 300
299 EXIT DO
CLOSE #1
GOTO 489
300 LOOP
CLOSE #1
301
tot = tot + 1
print a;b;c;d;e
489 NEXT t
490 NEXT e
491 NEXT d
492 NEXT c
493 NEXT b
494 NEXT a
What am I doing wrong?
Is there a better way to write the program?
Is there a way to get past the out of memory issue with Qbasic?
Ta
Mick
RE: Number generator comapred to number list
Seem to recall that there was an environment statement in DOS that would expand available memory.
Ed Fair
Give the wrong symptoms, get the wrong solutions.
RE: Number generator comapred to number list
Without a doubt :)
Is there a way to get past the out of memory issue with Qbasic?
Don't use 5 nested loops that read a 600 line file every iteration. (34 * 34 * 34 * 34 * 34 = WAY out of memory [for qbasic])
I don't understand what you are trying to do. Can you re-explain.
-Geates
http://ns7.webmasters.com/caspdoc/html/vbscript_la...
RE: Number generator comapred to number list
Basically I am generating all lottery numbers from 1 to 39 in order. It is a 5 ball draw. Then I want to compared it to a draw history of numbers that have that have already appeared.I want it to print out all these numbers and to ignore number combinations that have already appeared, e.g. if 2,5,17,23,24 has appeared, it wont print it . In my case I want to compare it to 4 numbers in a line of 5, e.g. if I have 1 2 3 4 5, there 5 number combinations to compare it to.
I managed to resolve the memory issue. I went back to using data read and now it is working. I went to setting and increased the allocated memory in properties. I was confuzzled as the file is smaller than 64kB. Geates it works but it does not give an out of memory error as it just prints to screen.
I am thinking there might be a function or another way to generate these numbers, as it is a bit slow scanning these numbers. I might add more filters later to it.
RE: Number generator comapred to number list
-Dan
http://ns7.webmasters.com/caspdoc/html/vbscript_la...
RE: Number generator comapred to number list
In creating the table of used numbers could you store them as alphanumeric rather than as numbers. Storing an array of 2 characters would be less memory intensive. Would, however, require a little more creative work in the generation of new numbers and the conversion to compare.
Rather than creating 39 new number sets at the beginning I would create them set by set and do the comparisons on the fly, stopping when I reached the 39 new ones.
How do you create the new numbers? Would assume you check for duplicates within a set.
Ed Fair
Give the wrong symptoms, get the wrong solutions.
RE: Number generator comapred to number list
As a noob I would if I could. I am comparing those numbers on the fly while the numbers are being generated. I am generating all combinations of numbers picked from 1 to 39. You will have 39!(39-4)!/5! possible combinations. you can check without opening the document for input.Duplicates are checked after the next functions.
I can do that Geates but i want ALL number compared, then compared how much tickets it will take.
RE: Number generator comapred to number list
assuming your 600 line file looks like
CODE
this will find and report all the unused first digits.
CODE
It's a start..
-Geates
http://ns7.webmasters.com/caspdoc/html/vbscript_la...
RE: Number generator comapred to number list
For this example, the previously use combinations ("used.txt") is created by the program. Notice, how I used characters and strings to represent unused numbers - thanks, Edfair, for the very good idea.
CODE
-Geates
http://ns7.webmasters.com/caspdoc/html/vbscript_la...
RE: Number generator comapred to number list
CODE
goes before "'compose unique lotto numbers"
-Geates
http://ns7.webmasters.com/caspdoc/html/vbscript_la...