1

I am writing an app that analyzes previous lottery Powerball drawings to increase the odds of winning. Here's what I have done so far:

I've brought in the complete drawings from a file like this: 06/29/2002 01 02 03 04 05 Powerball: 01 I've cut out the numbers, so I can loop through them and fill an array with the numbers and the number of times that number has been drawn. I would like to grab the number of times any particular number was drawn, and the number, i.e. the numbers 1 and 44 were drawn 108 times. I want to store the data in a frequency grid like this, 1, 44 = 108 (the number 1 and 44 were drawn 108 times). Here's the code I have so far for this:

Private Class GetNumberFrequency
    Public ReadOnly Property GetFrequencyGrid() As String
        Get
           'Get/Set Variables
            Dim Size As Integer = CInt((Globals.UsersNumbers.Length /3))
            Dim TempNumber As Integer = 0
            Dim Frequency(59) As Integer   
            Dim Temp1 As Integer = 0
            Dim SortedFrequency1(59) As Integer
            Dim SortedFrequency2(59) As Integer
            Dim Start As Integer = 0

             For x As Integer = 0 To Size - 1 Step 1
                TempNumber = CInt(Globals.UsersNumbers.Substring(Start, 3).TrimStart)
                Frequency(TempNumber) += 1
                Start += 3
            Next

            For i As Integer = 1 To Frequency.Length - 1 Step 1
                Temp1 = Frequency(i) 'Get a number

                For j As Integer = 1 To Frequency.Length - 1 Step 1
                    If Frequency(j) = Temp1 Then
'Here is where I am having the problem.
'I cant figure out the logic to use here.
'Right now the array holds the numbers and the number of times they
'were drawn,
'i.e. Frequency(1) = 108
      Frequency(2) = 117
      Frequency(3) = 106
      Frequency(44) = 108
'I want to loop through the array values 108, 117, 106 and grab 
'the indexes of each of these number draw frequencies (1, 2, 3, etc.), 
'so I can display them as,
    'Numbers    Frequency
    '1, 44        108
    '7, 25        117, etc. 
'I've tried using a 2 dimensional array but the array of Frequency(60, 60)
'creates an array of 3600 elements, and I don't need that many.
'I've also tried an array for the numbers and a string for the number of
'times drawn, but the logic escapes me.
'Any help will be appreciated! Thank you.
                    End If
                Next
            Next
            Return Frequency.ToString
        End Get
    End Property
End Class
2
  • 1
    You could just go to the powerball website... powerball.com/powerball/pb_frequency.asp While this may provide you with a misguided method for selecting numbers, it unfortunately won't increase your odds of actually winning. Commented Aug 14, 2015 at 18:12
  • Adding Step 1 is redundant as it is the default step. Commented Aug 14, 2015 at 18:39

1 Answer 1

1

Generic lists and dictionaries are a great way to store and organize information (instead of arrays). For this purpose, I'll start by generating some random data since I don't have the set you are working with.

A Dictionary stores data as Key-Value pairs and can be constructed for nearly any conceivable type. The keys are unique and each key links to one value.

In this case I want to first store the raw data in a dictionary whose keys will be of Integer type and which will represent the ball numbers. The value for the dictionary will also be of Integer type and will hold the frequency with which the ball has historically been drawn.

    ' store frequencies in a dictionary (ball number, draw count)
    Dim Frequencies As New Dictionary(Of Integer, Integer)
    Dim r As New Random()
    'generate some random frequency values
    Dim i As Integer
    For i = 1 To 59  'ball numbers 1->59
        Frequencies.Add(i, r.Next(10))
    Next

Next, we want to group balls by their draw frequency. Here I am again using a dictionary, but this time the key is an Integer representing the frequency count. A dictionary is again useful here since the objective is to have the frequency count be unique and to associate it with a list of balls drawn with that frequency. The value portion of the dictionary, therefore, is a list of ball numbers (integers) - List(Of Integer).

    Dim BallsByFreq As New Dictionary(Of Integer, List(Of Integer))

    For Each ballCount As KeyValuePair(Of Integer, Integer) In Frequencies
        Dim ballNumber As Integer = ballCount.Key
        Dim ballFrequency As Integer = ballCount.Value
        If BallsByFreq.ContainsKey(ballFrequency) Then
            'dictionary already contains an entry for this frequency
            'add the current ball number to the list 
            BallsByFreq(ballFrequency).Add(ballNumber)
        Else
            'dictionary does not contain an entry for this frequency
            'make a new list with this ball and it to the dictionary
            Dim newList As New List(Of Integer)
            newList.Add(ballNumber)
            BallsByFreq.Add(ballFrequency, newList)
        End If
    Next

Then, to generate your output simply enumerate over the dictionary. A dictionary can't be sorted, but we can extract the keys and sort them, then index the dictionary using the sorted list of keys.

    ' extract all the keys (frequencies) and sort them
    Dim f As New List(Of Integer)
    For Each k As Integer In BallsByFreq.Keys
        f.Add(k)
    Next
    f.Sort()
    f.Reverse() 'want highest first

    For Each freq As Integer In f
        Dim outline As String
        outline = "Frequency : " & freq.ToString("000") & ", Balls : "
        'Sort ball numbers to be pretty
        BallsByFreq(freq).Sort()
        For Each ball As Integer In BallsByFreq(freq)
            outline = outline & ball.ToString("00") & " "
        Next
        Console.WriteLine(outline)
    Next

In a console application the above generates output

Frequency : 009, Balls : 19 21 23 25 34 45
Frequency : 008, Balls : 01 06 31 50 58
Frequency : 007, Balls : 11 40 51 57
Frequency : 006, Balls : 02 14 17 29 39 46
Frequency : 005, Balls : 05 24 38 41 44
Frequency : 004, Balls : 03 07 10 12 22 48 54
Frequency : 003, Balls : 09 18 36 47 53 56
Frequency : 002, Balls : 04 15 26 32 42 43 49 52 55 59
Frequency : 001, Balls : 08 16 20 33 35
Frequency : 000, Balls : 13 27 28 30 37

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you J... I am coding that now. I'll let you know how it goes since I'm a beginner at vb.net
How do I add another question concerning this answer?
@JimConace I think this is substantial enough. If you have a new question then the best course is to post a new question. Your original question was quite broad so a new, more specific question dealing with the content of this answer would probably be both a better question and more on-topic.
@JimConace Keep in mind that the purpose of Stack Overflow is not necessarily to provide a solution to your project in one place, but rather to generate small, broadly useful questions and answers that have lasting value to a broader audience. A dense QA solving your particular problem will likely not have lasting value, but the many questions you need answers to along the way likely do. Try to break your project into small steps and ask separate questions at each place you get stuck. The more specific and narrow in scope, the more likely the answer will have utility to many other people.
Thank you J... I will do that. Thanks again for your patience, lol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.