Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Who here is VERY good at troubleshooting QB programs?
#54
Quote:To find the probability it goes through the numbers finding which numbers occur the most and remembers them.
I thought so. It seems then that you need a sorting algorithm, not a mathematical one:
Code:
'' [ ...fill entries array with user numbers... ]

   dim setIndex as integer : dim entryIndex as integer
   '' for all user sets ...
   for setIndex = 0 to totalsets - 1
      '' for all entries ...
      for entryIndex = 0 to MAXENTRIES - 1
         dim number as integer : number = entries( setIndex, entryIndex )
         if( number = 0 ) then               '' move to next set when 1st zero is
            exit for                         '' encountered; 0 denotes end of set
         end if
         '' increment the frequency of that number
         frequency( number ) = frequency( number ) + 1
      next
   next
  
   '' { now we have an array, frequency, that tells us }
   '' { the frequency of the numbers 1..52 }

   '' we can sort this array by frequency, using any number of algorithms. The
   '' simplest would probably be the bubble-sort :

   '' - BubbleSort ------------------------------------------------------------ ''
      dim Limit as integer : Limit = ubound( frequency )
      dim LastSwap as integer                '' the last necessary swap
      Do
         LastSwap = 0                        '' reset our swap position
         For number = 1 To ( Limit - 1 )     '' sort from beginning to our limit

            '' Two adjacent numbers are out of order, so swap their values
            If( frequency(number).Length < frequency(number + 1).Length ) Then
               Swap frequency(number), frequency(number + 1)
               LastSwap = number             '' remember position of last swap
            End If
         Next number
                                             '' set limit to last necessary swap;
         Limit = LastSwap                    '' the numbers after that swap
                                             '' are already in order

      Loop While LastSwap                    '' make passes until no swaps are done
   '' - /BubbleSort ----------------------------------------------------------- ''
  
   '' { our frequency array is now sorted from highest to lowest }

   '' Now we can display the top X recurring numbers:
   print "Ten most recurring numbers entered:"
   dim luckyNumber as integer
   for luckyNumber = 1 to 10
      print frequency( luckyNumber )
   next luckyNumber
stylin:
Reply


Messages In This Thread
Who here is VERY good at troubleshooting QB programs? - by Anonymous - 10-13-2005, 09:44 AM
Who here is VERY good at troubleshooting QB programs? - by Anonymous - 11-02-2005, 08:42 AM
Who here is VERY good at troubleshooting QB programs? - by stylin - 11-15-2005, 12:04 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)