Welcome Guest
Log In | Register )
You last visited December 5, 2016, 9:28 am
All times shown are
Eastern Time (GMT-5:00)

C Code For Finding P4 Key Numbers

Topic closed. 3 replies. Last post 8 years ago by jayemmar.

Page 1 of 1
PrintE-mailLink
Avatar

United States
Member #7437
October 3, 2004
383 Posts
Offline
Posted: March 24, 2009, 6:02 pm - IP Logged

Hi:

 

Below the asterisks you'll find the C code for the program we wrote called, keyNumberFinderP4.

This program finds sets of 4 numbers, which are key numbers to the next draw. In the case that more than one set of key numbers are generated, pick a set and stay with it. We've had very good results with the program.

Requirements:

1. Copy the C code below the asterisks into your compiler's editor and save as keyNumberFinderP4.c

2. Compile the C code as a C console application.

3. Create a past draw text file of 20 draws, called drawsP4.txt. Latest draw on top, oldest draw on bottom. One draw per line, no spaces or delimiters. The drawsP4.txt file should be in the same directory as keyNumberFinderP4.exe

5. To run the program, click on the keyNumberFinderP4.exe icon. You will see the results in a seperate window.

6. Update the draw file daily. This will provide you with the best key numbers.

7. Very often you'll find that a pair within the 4 key numbers hits on the upcoming draw, and sometimes 3 out of the 4 key numbers hit on the upcoming draw.

Good luck.

************************************************************************

#include <math.h>
#include <stdlib.h>
#include <stdio.h>

int main()
{
int i, j , k, temp1, temp2, temp3, temp4, a1, a2, a3, a4, a;
int drawCount, hit,  percent,  results;
int  twoHits;
FILE *in, *out;
int drawArray[50];

int arrayOfFours[210] =
{123,124,125,126,127,128,129,134,135,136,137,138,139,
145,146,147,148,149,156,157,158,159,167,168,169,178,
179,189,234,235,236,237,238,239,245,246,247,248,249,
256,257,258,259,267,268,269,278,279,289,345,346,347,
348,349,356,357,358,359,367,368,369,378,379,389,456,
457,458,459,467,468,469,478,479,489,567,568,569,578,
579,589,678,679,689,789,1234,1235,1236,1237,1238,1239,1245,
1246,1247,1248,1249,1256,1257,1258,1259,1267,1268,1269,1278,1279,
1289,1345,1346,1347,1348,1349,1356,1357,1358,1359,1367,1368,1369,
1378,1379,1389,1456,1457,1458,1459,1467,1468,1469,1478,1479,1489,
1567,1568,1569,1578,1579,1589,1678,1679,1689,1789,2345,2346,2347,
2348,2349,2356,2357,2358,2359,2367,2368,2369,2378,2379,2389,2456,
2457,2458,2459,2467,2468,2469,2478,2479,2489,2567,2568,2569,2578,
2579,2589,2678,2679,2689,2789,3456,3457,3458,3459,3467,3468,3469,
3478,3479,3489,3567,3568,3569,3578,3579,3589,3678,3679,3689,3789,
4567,4568,4569,4578,4579,4589,4678,4679,4689,4789,5678,5679,5689,
5789,6789};


      /*
      **Open files
      */
       in = fopen("drawsP4.txt", "r");
       if(in == NULL)
       {
          printf("error in opening drawsP4.txt\n");
          getch();
          exit(0); 
       }



       i = 0;
       while(!feof(in) && i < 20)
       {
           fscanf(in, "%d", &a);
           drawArray[i] = a;
           i++;
           drawCount++;           
       }
       drawCount = i;

       results = 0; 
start:     
       for(i = 0; i < 210; i++)
       {     hit = 0;
             temp1 = arrayOfFours[i]/1000;
             temp2 = (arrayOfFours[i] - 1000*temp1)/100;
             temp3=  (arrayOfFours[i] - 1000*temp1 - 100*temp2)/10;
             temp4 = (arrayOfFours[i] - 1000*temp1 - 100*temp2 - 10*temp3);

             for(j = 0; j < drawCount; j++)
             {
                a = drawArray[j];           
                a1 = a/1000;
                a2 = (a - 1000*a1)/100;
                a3=  (a - 1000*a1 - 100*a2)/10;
                a4 = (a - 1000*a1 - 100*a2 - 10*a3);
               
                twoHits = 0;
                if((a1 == temp1 || a1 == temp2 || a1 == temp3 || a1 == temp4))
                {
                    twoHits++; 
                }
                if((a2 == temp1 || a2 == temp2 || a2 == temp3 || a2 == temp4))
                {
                   twoHits++;   
                }
                if((a3 == temp1 || a3 == temp2 || a3 == temp3 || a3 == temp4))
                {
                   twoHits++;   
                }
                if((a4 == temp1 || a4 == temp2 || a4 == temp3 || a4 == temp4))
               {
                  twoHits++;
               }   
               if(twoHits >= 2)
               {
                  hit++;       
               }
                           
             }
           
             
             if(hit == drawCount)
             {
                printf("Key Number Set -> %i-%i-%i-%i\n",
                        temp1,  temp2, temp3, temp4);
                       
                results = 1;
             }
               
                 

       } 


       if(results == 0)
       {
            drawCount = drawCount - 1;
            goto start;
       }

       printf("Number of past draws used was %i\n", drawCount);
       printf("Enter any key to exit\n");
       getch();
     
       close(in);


}

    Avatar

    United States
    Member #7437
    October 3, 2004
    383 Posts
    Offline
    Posted: March 25, 2009, 11:55 am - IP Logged

    Hi:

     

    Sorry for this, but there seems to be a bug in the original code. What we are going to do here is keep the original requirement that at least one number in the key number set has to appear in the a maximum number of the most recent past draws. We know the code we wrote for this scenario is correct, and it is reflected below the asterisks.

     

    Will post revised sets of key numbers for some states later on.

    jayemmar

     

     

    ************************************************************************

    #include <math.h>
    #include <stdlib.h>
    #include <stdio.h>

    int main()
    {
    int i, j , k, temp1, temp2, temp3, temp4, a1, a2, a3, a4, a;
    int drawCount, hit,  percent,  results;
    int  twoHits;
    FILE *in, *out;
    int drawArray[50];

    int arrayOfFours[210] =
    {123,124,125,126,127,128,129,134,135,136,137,138,139,
    145,146,147,148,149,156,157,158,159,167,168,169,178,
    179,189,234,235,236,237,238,239,245,246,247,248,249,
    256,257,258,259,267,268,269,278,279,289,345,346,347,
    348,349,356,357,358,359,367,368,369,378,379,389,456,
    457,458,459,467,468,469,478,479,489,567,568,569,578,
    579,589,678,679,689,789,1234,1235,1236,1237,1238,1239,1245,
    1246,1247,1248,1249,1256,1257,1258,1259,1267,1268,1269,1278,1279,
    1289,1345,1346,1347,1348,1349,1356,1357,1358,1359,1367,1368,1369,
    1378,1379,1389,1456,1457,1458,1459,1467,1468,1469,1478,1479,1489,
    1567,1568,1569,1578,1579,1589,1678,1679,1689,1789,2345,2346,2347,
    2348,2349,2356,2357,2358,2359,2367,2368,2369,2378,2379,2389,2456,
    2457,2458,2459,2467,2468,2469,2478,2479,2489,2567,2568,2569,2578,
    2579,2589,2678,2679,2689,2789,3456,3457,3458,3459,3467,3468,3469,
    3478,3479,3489,3567,3568,3569,3578,3579,3589,3678,3679,3689,3789,
    4567,4568,4569,4578,4579,4589,4678,4679,4689,4789,5678,5679,5689,
    5789,6789};


          /*
          **Open files
          */
           in = fopen("drawsP4.txt", "r");
           if(in == NULL)
           {
              printf("error in opening drawsP4.txt\n");
              getch();
              exit(0); 
           }



           i = 0;
           while(!feof(in) && i < 20)
           {
               fscanf(in, "%d", &a);
               drawArray[i] = a;
               i++;
               drawCount++;           
           }
           drawCount = i;

           results = 0; 
    start:     
           for(i = 0; i < 210; i++)
           {     hit = 0;
                 temp1 = arrayOfFours[i]/1000;
                 temp2 = (arrayOfFours[i] - 1000*temp1)/100;
                 temp3=  (arrayOfFours[i] - 1000*temp1 - 100*temp2)/10;
                 temp4 = (arrayOfFours[i] - 1000*temp1 - 100*temp2 - 10*temp3);

                 for(j = 0; j < drawCount; j++)
                 {
                    a = drawArray[j];           
                    a1 = a/1000;
                    a2 = (a - 1000*a1)/100;
                    a3=  (a - 1000*a1 - 100*a2)/10;
                    a4 = (a - 1000*a1 - 100*a2 - 10*a3);
                   
                    twoHits = 0;
                    if((a1 == temp1 || a1 == temp2 || a1 == temp3 || a1 == temp4))
                    {
                        twoHits++; 
                    }
                    if((a2 == temp1 || a2 == temp2 || a2 == temp3 || a2 == temp4))
                    {
                       twoHits++;   
                    }
                    if((a3 == temp1 || a3 == temp2 || a3 == temp3 || a3 == temp4))
                    {
                       twoHits++;   
                    }
                    if((a4 == temp1 || a4 == temp2 || a4 == temp3 || a4 == temp4))
                   {
                      twoHits++;
                   }

                   /*

                   ** Change to one match on the key number set; used to be 2

                  */

                   if(twoHits == 1)
                   {
                      hit++;       
                   }
                               
                 }
               
                 
                 if(hit == drawCount)
                 {
                    printf("Key Number Set -> %i-%i-%i-%i\n",
                            temp1,  temp2, temp3, temp4);
                           
                    results = 1;
                 }
                   
                     

           } 


           if(results == 0)
           {
                drawCount = drawCount - 1;
                goto start;
           }

           printf("Number of past draws used was %i\n", drawCount);
           printf("Enter any key to exit\n");
           getch();
         
           close(in);


    }

      Avatar

      United States
      Member #33295
      February 19, 2006
      699 Posts
      Offline
      Posted: March 25, 2009, 1:07 pm - IP Logged

      Thanks for the code, Jayemmar!!!

      I am taking a C++ class this semester and this is pretty interesting stuff to me.

      Bud

      Isabel, you are going to feel very silly when this turns out to be make-believe.

        Avatar

        United States
        Member #7437
        October 3, 2004
        383 Posts
        Offline
        Posted: March 26, 2009, 10:16 am - IP Logged

        We finally corrected the intended version of the key number finder for the P4. The confusion was that the code counted a double pair as two distinct numbers. So when the key numbers were, for example 2-4-6-8 and a past draw was say, 8644, the program would say that the draw contained at least 2 numbers in the key number set(the two 4s). This is could be argued from both sides, and we are going to leave the double count as it stays.

        Below the asterisks is the C code for the P4 key number finder, corrected.

        Follow instuctions from the previous posts for compilation and installation setails.

        As to how long the key numbers are good for, this needs some input from you. We keep waivering between 1 and 5 days.

        As promised, here are the key number picks for some states. We tried to get them in early before the midday draw. Also, we combined the midday and eve results into one draw file. You may get better results if you keep them seperate. Again this needs some input from you.

        In case anyone has no experience with compiling code, send me a PM with contact info.

        Ultimately we'd like to use the results of the key number finder to come up with a selection system for the P4.

        NY Day and Eve: Set1 -> 0-6-7-8

                                    Set2 -> 3-6-7-8

                                    Set3 -> 4-6-7-8

         

        NJ Day and Eve: Set1 -> 0-1-2-4

        Ga Day and eve: Set1 -> 1-2-3-5

        jayemmar

         

         

        ****************************************************************************

        #include <math.h>
        #include <stdlib.h>
        #include <stdio.h>

        int main()
        {
        int i, j , k, temp1, temp2, temp3, temp4, a1, a2, a3, a4, a;
        int drawCount, hit,  percent,  results;
        int  twoHitsa1 = 0, twoHitsa2 = 0, twoHitsa3 = 0, twoHitsa4 = 0;
        FILE *in, *out;
        int drawArray[50];

        int arrayOfFours[210] =
        {123,124,125,126,127,128,129,134,135,136,137,138,139,
        145,146,147,148,149,156,157,158,159,167,168,169,178,
        179,189,234,235,236,237,238,239,245,246,247,248,249,
        256,257,258,259,267,268,269,278,279,289,345,346,347,
        348,349,356,357,358,359,367,368,369,378,379,389,456,
        457,458,459,467,468,469,478,479,489,567,568,569,578,
        579,589,678,679,689,789,1234,1235,1236,1237,1238,1239,1245,
        1246,1247,1248,1249,1256,1257,1258,1259,1267,1268,1269,1278,1279,
        1289,1345,1346,1347,1348,1349,1356,1357,1358,1359,1367,1368,1369,
        1378,1379,1389,1456,1457,1458,1459,1467,1468,1469,1478,1479,1489,
        1567,1568,1569,1578,1579,1589,1678,1679,1689,1789,2345,2346,2347,
        2348,2349,2356,2357,2358,2359,2367,2368,2369,2378,2379,2389,2456,
        2457,2458,2459,2467,2468,2469,2478,2479,2489,2567,2568,2569,2578,
        2579,2589,2678,2679,2689,2789,3456,3457,3458,3459,3467,3468,3469,
        3478,3479,3489,3567,3568,3569,3578,3579,3589,3678,3679,3689,3789,
        4567,4568,4569,4578,4579,4589,4678,4679,4689,4789,5678,5679,5689,
        5789,6789};


              /*
              **Open files
              */
               in = fopen("drawsP4.txt", "r");
               if(in == NULL)
               {
                  printf("error in opening drawsP4.txt\n");
                  getch();
                  exit(0); 
               }



               i = 0;
               drawCount = 0;
               while(!feof(in) && i < 20)
               {
                   fscanf(in, "%d", &a);
                   drawArray[i] = a;
                   i++;
                   drawCount++;           
               }
               drawCount = i;

               results = 0; 
        start:
               hit = 0;     
               for(i = 0; i < 210; i++)
               {     hit = 0;
                     temp1 = arrayOfFours[i]/1000;
                     temp2 = (arrayOfFours[i] - 1000*temp1)/100;
                     temp3=  (arrayOfFours[i] - 1000*temp1 - 100*temp2)/10;
                     temp4 = (arrayOfFours[i] - 1000*temp1 - 100*temp2 - 10*temp3);

                     for(j = 0; j < drawCount; j++)
                     {
                        a = drawArray[j];           
                        a1 = a/1000;
                        a2 = (a - 1000*a1)/100;
                        a3=  (a - 1000*a1 - 100*a2)/10;
                        a4 = (a - 1000*a1 - 100*a2 - 10*a3);
                       
                       
                        twoHitsa1 = 0;   
                        twoHitsa2 = 0;   
                        twoHitsa3 = 0;   
                        twoHitsa4 = 0;   
                        if((a1 == temp1 || a1 == temp2 || a1 == temp3 || a1 == temp4))
                        {
                            twoHitsa1++; 
                        }
                        if((a2 == temp1 || a2 == temp2 || a2 == temp3 || a2 == temp4))
                        {
                           twoHitsa2++;   
                        }
                        if((a3 == temp1 || a3 == temp2 || a3 == temp3 || a3 == temp4))
                        {
                           twoHitsa3++;   
                        }
                        if((a4 == temp1 || a4 == temp2 || a4 == temp3 || a4 == temp4))
                       {
                          twoHitsa4++;
                       }   
                       if(twoHitsa1 + twoHitsa2 + twoHitsa3 + twoHitsa4   > 1)
                       {
                          hit++;
                       }
                                   
                     }
                     
                     if(hit == drawCount)
                     {
                        printf("Key Number Set -> %i-%i-%i-%i\n",
                                temp1,  temp2, temp3, temp4);
                        results = 1;
                     }
                       
                         

               } 



               if(results == 0)
               {
                    drawCount = drawCount - 1;
                    goto start;
               }

               printf("Number of past draws used was %i\n", drawCount);
               printf("Enter any key to exit\n");
               getch();
             
               close(in);


        }