View unanswered posts | View active topics It is currently Tue Apr 21, 2026 10:14 am



Reply to topic  [ 1 post ] 
 Just for Fun - Lottery Numbers 
Author Message
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Just for Fun - Lottery Numbers
k, this won't give you the next winning numbers for the lottery so forget that.

What you need is a text list of the numbers (in this case PowerBall) that has 5 regular numbers and 1 "hot ball" number per line. The script will output the number of times a number has been hit from the list. Up to you if you want to pick the highest numbers hit, or the lowest in hope that it is their "turn".

Code:
# setup two static arrays of size of 60, you could use dynamic arrays if you wanted to
setArray $number 60
setArray $hot 60

:begin
  setVar $nextLine 1

  # read the first line of our data file
  read "lottery.txt" $line 1

# setup while/end loop to detect the file EOF
  while ($line <> EOF)
      # setup counter for parsing the line read from a file
       setVar $i 1
      # we know there are 6 numbers in the line so while $i <= 6
       while ($i <=6)
         # get the $i position word of the line
         getword $line $num $i
         # if $i = 6 we know it is the "hot ball" so store it in that array
         if ($i = 6)
            add $hot[$num] 1
         else
         # wasn't the "hot ball" so it is one of the "regular" numbers and store in that array
         add $number[$num] 1
         end
         # increment our counter for parsing the line
         add $i 1
       end
  # add 1 to our file line counter
  add $nextLine 1
  # read the new line
  read "lottery.txt" $line $nextLine
end

# reset $i to 1 so we can output our results
setVar $i 1
while ($i <= 60)
# write our results to a new file
write "loteryResults.txt" $i & "," & $number[$i] & "," & $hot[$i]
add $i 1
end
# win the lottery and send Promethius 5% (I'm not greedy)


If you want to extend this a bit, you could add a sort routine to sort the output base on the number of hits and split out the "normal" vs "hot ball" numbers. Add a timer to the start and end of the sort and get some information on performance although an array of 60 should be fairly quick to sort.

[Edit] The pre /pre codes I was using made it hard to read so I've switch to the code /code tags. [/edit]

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Fri Dec 05, 2008 2:27 pm
Profile ICQ
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.