+DECLARE SUB loadData ()\r
+DECLARE SUB predictNextDraw ()\r
+DECLARE SUB parseDrawNumbers (drawString$)\r
+DECLARE SUB displayDotGraph ()\r
+DECLARE SUB waitForUserInput ()\r
+DECLARE SUB displayLineGraph ()\r
+DECLARE SUB displayCombinatoricsGraph ()\r
+DECLARE SUB displayMenu ()\r
+DECLARE SUB startProgram ()\r
' Program to analyze lottery winning numbers.\r
' By Svjatoslav Agejenko.\r
' Email: svjatoslav@svjatoslav.eu\r
' Homepage: http://www.svjatoslav.eu\r
-'\r
+\r
' Changelog:\r
' 2001, Initial version\r
-' 2024.09, Improved program readability using AI\r
+' 2024, Improved program readability using AI\r
\r
DEFINT A-Y\r
\r
-DIM SHARED mitus, sona$(1 TO 50)\r
-DIM SHARED num(1 TO 500, 1 TO 7)\r
-DIM SHARED mitun\r
-\r
-start\r
-loaddata\r
+DIM SHARED totalDraws, drawNumbers$(1 TO 50)\r
+DIM SHARED lotteryNumbers(1 TO 500, 1 TO 7)\r
+DIM SHARED currentDraw\r
\r
-menu\r
-\r
-SUB ennus\r
- DIM buf(1 TO 48)\r
- PRINT "During the last 10 draws:"\r
+startProgram\r
+loadData\r
\r
- ' Count occurrences of each number in the last 10 draws\r
- FOR a = mitun - 10 TO mitun\r
- FOR b = 2 TO 7\r
- buf(num(a, b)) = buf(num(a, b)) + 1\r
- NEXT b\r
- NEXT a\r
-\r
- ' Print the most frequent numbers\r
- FOR b = 1 TO 6\r
- c = 0\r
- FOR a = 1 TO 48\r
- IF buf(a) > c THEN c = buf(a): d = a\r
- NEXT a\r
- PRINT d; " appeared: "; c; " times"\r
- buf(d) = 0\r
- NEXT b\r
+displayMenu\r
\r
- PRINT "--------------------------------------"\r
+SUB displayCombinatoricsGraph\r
+ CLS\r
+ PAINT (1, 1), 3\r
+ DIM buffer(1 TO 48)\r
+ DIM buffer2(1 TO 20000)\r
\r
- ' Find when each number last appeared\r
- FOR a = 1 TO mitun\r
- FOR b = 2 TO 7\r
- buf(num(a, b)) = a\r
- NEXT b\r
- NEXT a\r
-\r
- FOR b = 1 TO 6\r
- c = 30000\r
- FOR a = 1 TO 48\r
- IF buf(a) < c THEN c = buf(a): d = a\r
- NEXT a\r
- PRINT d; " appeared last time: "; mitun - c; " draws ago"\r
- buf(d) = 30000\r
- NEXT b\r
+ totalNumbers = 0\r
\r
-END SUB\r
+ ' Prepare data for drawing\r
+ FOR drawIndex = 1 TO currentDraw\r
+ FOR number = 1 TO 48\r
+ buffer(number) = 0\r
+ NEXT number\r
\r
-SUB getson (a$)\r
- mitus = 0\r
+ FOR numberPosition = 2 TO 7\r
+ buffer(lotteryNumbers(drawIndex, numberPosition)) = 10\r
+ NEXT numberPosition\r
\r
- d = 1\r
- FOR b = 1 TO LEN(a$)\r
- c$ = RIGHT$(LEFT$(a$, b), 1)\r
- IF c$ = " " THEN\r
- d = 1\r
- ELSE\r
- IF d = 1 THEN\r
- mitus = mitus + 1\r
- sona$(mitus) = ""\r
- d = 0\r
- END IF\r
- sona$(mitus) = sona$(mitus) + c$\r
- END IF\r
- NEXT b\r
+ FOR number = 1 TO 48\r
+ totalNumbers = totalNumbers + 1\r
+ buffer2(totalNumbers) = buffer(number)\r
+ NEXT number\r
+ NEXT drawIndex\r
\r
+ ' Draw the graph\r
+ FOR yAxisValue = 2 TO 400\r
+ xAxisValue = 0\r
+ FOR xPosition = 1 TO 639\r
+ FOR yPosition = 1 TO yAxisValue\r
+ xAxisValue = xAxisValue + 1\r
+ IF xAxisValue > totalNumbers THEN GOTO skipDrawing\r
+ PSET (xPosition, yPosition), buffer2(xAxisValue)\r
+ NEXT yPosition\r
+ NEXT xPosition\r
+skipDrawing:\r
+\r
+ LINE (xPosition + 1, 1)-(xPosition + 1, yAxisValue), 14\r
+ LINE (xPosition + 1, yPosition)-(xPosition + 4, yPosition), 12\r
+\r
+ IF INKEY$ <> "" THEN GOTO 1\r
+ NEXT yAxisValue\r
+\r
+waitForUserInput\r
+1\r
END SUB\r
\r
-SUB gr1\r
+SUB displayDotGraph\r
CLS\r
LINE (0, 0)-(600, 0), 1\r
LINE (0, 49)-(600, 49), 1\r
LINE (0, 48 * 6 + 51)-(600, 48 * 6 + 51), 1\r
\r
' Draw vertical lines for each draw and plot numbers\r
- FOR a = 1 TO mitun\r
- c = 0\r
- FOR b = 2 TO 7\r
- c = c + num(a, b)\r
- PSET (a, num(a, b)), 15\r
- NEXT b\r
- LINE (a, c + 50)-(a, 24 * 6 + 50), 10\r
- NEXT a\r
-\r
- wai\r
+ FOR drawIndex = 1 TO currentDraw\r
+ totalNumbers = 0\r
+ FOR numberPosition = 2 TO 7\r
+ totalNumbers = totalNumbers + lotteryNumbers(drawIndex, numberPosition)\r
+ PSET (drawIndex, lotteryNumbers(drawIndex, numberPosition)), 15\r
+ NEXT numberPosition\r
+ LINE (drawIndex, totalNumbers + 50)-(drawIndex, 24 * 6 + 50), 10\r
+ NEXT drawIndex\r
+\r
+ waitForUserInput\r
END SUB\r
\r
-SUB gr2\r
+SUB displayLineGraph\r
CLS\r
- DIM buf(1 TO 20000)\r
+ DIM buffer(1 TO 20000)\r
\r
' Draw lines connecting consecutive lottery numbers\r
- FOR x = 1 TO mitun - 1\r
- FOR a = 2 TO 7\r
- LINE (600, num(x, a))-(610, num(x + 1, a)), 3\r
- NEXT a\r
+ FOR x = 1 TO currentDraw - 1\r
+ FOR numberPosition = 2 TO 7\r
+ LINE (600, lotteryNumbers(x, numberPosition))-(610, lotteryNumbers(x + 1, numberPosition)), 3\r
+ NEXT numberPosition\r
LINE (600, 1)-(600, 48), 1\r
SOUND 0, 2\r
\r
' Scroll the screen to the left\r
- GET (10, 1)-(610, 50), buf(1)\r
- PUT (1, 1), buf(1), PSET\r
+ GET (10, 1)-(610, 50), buffer(1)\r
+ PUT (1, 1), buffer(1), PSET\r
LINE (601, 1)-(610, 50), 0, BF\r
\r
IF INKEY$ <> "" GOTO 5\r
NEXT x\r
\r
- wai\r
- 5\r
+ waitForUserInput\r
+5\r
END SUB\r
\r
-SUB gr3\r
+SUB displayMenu\r
+menuLoop:\r
CLS\r
- PAINT (1, 1), 3\r
- DIM buf(1 TO 48)\r
- DIM buf2(1 TO 20000)\r
\r
- c = 0\r
+7\r
+ LOCATE 1, 1\r
\r
- ' Prepare data for drawing\r
- FOR a = 1 TO mitun\r
- FOR b = 1 TO 48\r
- buf(b) = 0\r
- NEXT b\r
+ PRINT " Lottery statistics analysis"\r
+\r
+ PRINT "1 - Dot graph"\r
+ PRINT "2 - Line graph"\r
+ PRINT "3 - Combinatorics"\r
+ PRINT "4 - Statistics"\r
+ PRINT "5 - Exit program"\r
\r
- FOR b = 2 TO 7\r
- buf(num(a, b)) = 10\r
- NEXT b\r
+ userInput$ = INPUT$(1)\r
\r
- FOR b = 1 TO 48\r
- c = c + 1\r
- buf2(c) = buf(b)\r
- NEXT b\r
- NEXT a\r
+ IF userInput$ = "1" THEN displayDotGraph\r
+ IF userInput$ = "2" THEN displayLineGraph\r
+ IF userInput$ = "3" THEN displayCombinatoricsGraph\r
+ IF userInput$ = "4" THEN predictNextDraw: GOTO 7\r
+ IF userInput$ = "5" THEN SYSTEM\r
+\r
+ GOTO menuLoop\r
\r
- ' Draw the graph\r
- FOR e = 2 TO 400\r
- d = 0\r
- FOR x = 1 TO 639\r
- FOR y = 1 TO e\r
- d = d + 1\r
- IF d > c THEN GOTO 4\r
- PSET (x, y), buf2(d)\r
- NEXT y\r
- NEXT x\r
- 4\r
-\r
- LINE (x + 1, 1)-(x + 1, e), 14\r
- LINE (x + 1, y)-(x + 4, y), 12\r
-\r
- IF INKEY$ <> "" THEN GOTO 6\r
- NEXT e\r
-\r
- wai\r
- 6\r
END SUB\r
\r
-SUB loaddata\r
+SUB loadData\r
PRINT "One moment..."\r
\r
- mitun = 0\r
+ currentDraw = 0\r
OPEN "loos.txt" FOR INPUT AS #1\r
\r
- 1\r
- IF EOF(1) <> 0 THEN GOTO 2\r
+loadNextLine:\r
+ IF EOF(1) <> 0 THEN GOTO endOfFile\r
\r
- LINE INPUT #1, a$\r
- getson a$\r
+ LINE INPUT #1, drawString$\r
+ parseDrawNumbers drawString$\r
\r
- mitun = mitun + 1\r
+ currentDraw = currentDraw + 1\r
\r
' Parse and store lottery numbers\r
- FOR b = 1 TO 7\r
- num(mitun, b) = VAL(sona$(b))\r
- NEXT b\r
+ FOR numberPosition = 1 TO 7\r
+ lotteryNumbers(currentDraw, numberPosition) = VAL(drawNumbers$(numberPosition))\r
+ NEXT numberPosition\r
\r
- GOTO 1\r
+ GOTO loadNextLine\r
\r
- 2\r
+endOfFile:\r
CLOSE #1\r
\r
CLS\r
END SUB\r
\r
-SUB menu\r
-3\r
- CLS\r
+SUB parseDrawNumbers (drawString$)\r
+ totalDraws = 0\r
\r
-7\r
- LOCATE 1, 1\r
+ numberIndex = 1\r
+ FOR charPosition = 1 TO LEN(drawString$)\r
+ currentChar$ = RIGHT$(LEFT$(drawString$, charPosition), 1)\r
+ IF currentChar$ = " " THEN\r
+ numberIndex = 1\r
+ ELSE\r
+ IF numberIndex = 1 THEN\r
+ totalDraws = totalDraws + 1\r
+ drawNumbers$(totalDraws) = ""\r
+ numberIndex = 0\r
+ END IF\r
+ drawNumbers$(totalDraws) = drawNumbers$(totalDraws) + currentChar$\r
+ END IF\r
+ NEXT charPosition\r
\r
- PRINT " Lottery statistics analysis"\r
+END SUB\r
\r
- PRINT "1 - Dot graph"\r
- PRINT "2 - Line graph"\r
- PRINT "3 - Combinatorics"\r
- PRINT "4 - Statistics"\r
- PRINT "5 - Exit program"\r
+SUB predictNextDraw\r
+ DIM buffer(1 TO 48)\r
+ PRINT "During the last 10 draws:"\r
\r
- a$ = INPUT$(1)\r
+ ' Count occurrences of each number in the last 10 draws\r
+ FOR drawIndex = currentDraw - 10 TO currentDraw\r
+ FOR numberPosition = 2 TO 7\r
+ buffer(lotteryNumbers(drawIndex, numberPosition)) = buffer(lotteryNumbers(drawIndex, numberPosition)) + 1\r
+ NEXT numberPosition\r
+ NEXT drawIndex\r
\r
- IF a$ = "1" THEN gr1\r
- IF a$ = "2" THEN gr2\r
- IF a$ = "3" THEN gr3\r
- IF a$ = "4" THEN ennus: GOTO 7\r
- IF a$ = "5" THEN SYSTEM\r
+ ' Print the most frequent numbers\r
+ FOR position = 1 TO 6\r
+ maxCount = 0\r
+ FOR number = 1 TO 48\r
+ IF buffer(number) > maxCount THEN\r
+ maxCount = buffer(number)\r
+ mostFrequentNumber = number\r
+ END IF\r
+ NEXT number\r
+ PRINT mostFrequentNumber; " appeared: "; maxCount; " times"\r
+ buffer(mostFrequentNumber) = 0\r
+ NEXT position\r
+\r
+ PRINT "--------------------------------------"\r
\r
- GOTO 3\r
+ ' Find when each number last appeared\r
+ FOR drawIndex = 1 TO currentDraw\r
+ FOR numberPosition = 2 TO 7\r
+ buffer(lotteryNumbers(drawIndex, numberPosition)) = drawIndex\r
+ NEXT numberPosition\r
+ NEXT drawIndex\r
+\r
+ FOR position = 1 TO 6\r
+ minAppearances = 30000\r
+ FOR number = 1 TO 48\r
+ IF buffer(number) < minAppearances THEN\r
+ minAppearances = buffer(number)\r
+ leastRecentNumber = number\r
+ END IF\r
+ NEXT number\r
+ PRINT leastRecentNumber; " appeared last time: "; currentDraw - minAppearances; " draws ago"\r
+ buffer(leastRecentNumber) = 30000\r
+ NEXT position\r
\r
END SUB\r
\r
-SUB start\r
+SUB startProgram\r
SCREEN 12\r
\r
END SUB\r
\r
-SUB wai\r
- a$ = INPUT$(1)\r
+SUB waitForUserInput\r
+ userInput$ = INPUT$(1)\r
\r
END SUB\r
+\r