Author Topic: question about PEEK and POKE - hello need to know what this is doing  (Read 6924 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: question about PEEK and POKE - hello need to know what this is doing
« Reply #30 on: October 28, 2020, 08:04:33 am »
Code: QB64: [Select]
  1. PRINT STR$((INT(RND * TIMER)) MOD 69 + 1); STR$((INT(RND * TIMER)) MOD 69 + 1); STR$((INT(RND * TIMER)) MOD 69 + 1); STR$((INT(RND * TIMER)) MOD 69 + 1); STR$((INT(RND * TIMER)) MOD 69 + 1); " Red Ball"; STR$((INT(RND * TIMER)) MOD 26 + 1)
  2.  

Probably not always right but what are the odds?

About 86.3% Good!

Code: QB64: [Select]
  1. 1 test$ = STR$((INT(RND * TIMER)) MOD 69 + 1) + STR$((INT(RND * TIMER)) MOD 69 + 1) + STR$((INT(RND * TIMER)) MOD 69 + 1) + STR$((INT(RND * TIMER)) MOD 69 + 1) + STR$((INT(RND * TIMER)) MOD 69 + 1) + " Red Ball" + STR$((INT(RND * TIMER)) MOD 26 + 1)
  2. REDIM p$(0)
  3. Split test$, " ", p$()
  4. noGoodF = 0
  5. FOR i = 1 TO 5
  6.     PRINT p$(i); ", ";
  7.     IF i > 1 THEN
  8.         FOR j = 1 TO i - 1
  9.             IF p$(i) = p$(j) THEN noGoodF = -1
  10.         NEXT
  11.     END IF
  12. IF noGoodF THEN
  13.     PRINT "No Good": NoGood = NoGood + 1
  14.     PRINT "Good!": good = good + 1
  15. testN = testN + 1
  16. IF testN < 100000 THEN GOTO 1
  17. PRINT "Good"; good; ", No Good"; NoGood
  18.  
  19. SUB Split (SplitMeString AS STRING, delim AS STRING, loadMeArray() AS STRING)
  20.     DIM curpos AS LONG, arrpos AS LONG, LD AS LONG, dpos AS LONG 'fix use the Lbound the array already has
  21.     curpos = 1: arrpos = LBOUND(loadMeArray): LD = LEN(delim)
  22.     dpos = INSTR(curpos, SplitMeString, delim)
  23.     DO UNTIL dpos = 0
  24.         loadMeArray(arrpos) = MID$(SplitMeString, curpos, dpos - curpos)
  25.         arrpos = arrpos + 1
  26.         IF arrpos > UBOUND(loadMeArray) THEN REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO UBOUND(loadMeArray) + 1000) AS STRING
  27.         curpos = dpos + LD
  28.         dpos = INSTR(curpos, SplitMeString, delim)
  29.     LOOP
  30.     loadMeArray(arrpos) = MID$(SplitMeString, curpos)
  31.     REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO arrpos) AS STRING 'get the ubound correct
  32.  
  33.  
  34.  

BTW it is 69 white balls
 https://www.google.com/search?client=opera&q=is+the+red+ball+of+power+ball+separate+from+the+other+69&sourceid=opera&ie=UTF-8&oe=UTF-8
Quote
The first five regular numbers, which are white balls, are drawn out of a drum with 69 balls; one Powerball, or red ball, is drawn from a separate drum with 26 balls. Matching all five regular numbers, or white balls, in any order and the red Powerball will win you the jackpot.Aug 15, 2017

« Last Edit: October 28, 2020, 08:53:57 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: question about PEEK and POKE - hello need to know what this is doing
« Reply #31 on: October 28, 2020, 10:29:13 am »
Alas, I found a slight flaw with Split ;-(

Oh wait if I trimmed test$, yes I do have a value for first = lower bound index in array, OK :)
Code: QB64: [Select]
  1. 1 test$ = STR$((INT(RND * TIMER)) MOD 69 + 1) + STR$((INT(RND * TIMER)) MOD 69 + 1) + STR$((INT(RND * TIMER)) MOD 69 + 1) + STR$((INT(RND * TIMER)) MOD 69 + 1) + STR$((INT(RND * TIMER)) MOD 69 + 1) + " Red Ball" + STR$((INT(RND * TIMER)) MOD 26 + 1)
  2. REDIM p$(0)
  3. Split _TRIM$(test$), " ", p$()
  4. noGoodF = 0
  5. FOR i = 0 TO 4
  6.     PRINT p$(i); ", ";
  7.     IF i > 0 THEN
  8.         FOR j = 0 TO i - 1
  9.             IF p$(i) = p$(j) THEN noGoodF = -1
  10.         NEXT
  11.     END IF
  12. IF noGoodF THEN
  13.     PRINT "No Good": NoGood = NoGood + 1
  14.     PRINT "Good!": good = good + 1
  15. testN = testN + 1
  16. IF testN < 100000 THEN GOTO 1
  17. PRINT "Good"; good; ", No Good"; NoGood
  18.  
  19. SUB Split (SplitMeString AS STRING, delim AS STRING, loadMeArray() AS STRING)
  20.     DIM curpos AS LONG, arrpos AS LONG, LD AS LONG, dpos AS LONG 'fix use the Lbound the array already has
  21.     curpos = 1: arrpos = LBOUND(loadMeArray): LD = LEN(delim)
  22.     dpos = INSTR(curpos, SplitMeString, delim)
  23.     DO UNTIL dpos = 0
  24.         loadMeArray(arrpos) = MID$(SplitMeString, curpos, dpos - curpos)
  25.         arrpos = arrpos + 1
  26.         IF arrpos > UBOUND(loadMeArray) THEN REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO UBOUND(loadMeArray) + 1000) AS STRING
  27.         curpos = dpos + LD
  28.         dpos = INSTR(curpos, SplitMeString, delim)
  29.     LOOP
  30.     loadMeArray(arrpos) = MID$(SplitMeString, curpos)
  31.     REDIM _PRESERVE loadMeArray(LBOUND(loadMeArray) TO arrpos) AS STRING 'get the ubound correct
  32.  

That's better use of split.
« Last Edit: October 28, 2020, 10:41:31 am by bplus »