Welcome Guest
Log In | Register )
You last visited December 3, 2016, 10:50 pm
All times shown are
Eastern Time (GMT-5:00)

New Version Of Key Numbers Finder For The P4

Topic closed. Posted 8 years ago. No replies.

Page 1 of 1
PrintE-mailLink
Avatar

United States
Member #7437
October 3, 2004
383 Posts
Offline
Posted: May 6, 2009, 11:43 am - IP Logged

Hi:

 

Many people have written to me about situations where they get a barrage of key number sets for some or even all of the 4 segments. To remedy this situation, all we have to do is go down deeper into the drawfile to make our analysis. So here are the changes.

1. Make the draw file(drawsP4.txt) so that it contains at least 50 of the past P4 draws. This is a strict requirement.

2. When you run the program, you'll be asked how far down in the draw file you want to go. Enter 20 to start, and if you get long lists of key numbers with 20, exit the program, run it again, and bump the depth to 30, etc. You should get resonable length lists with this change. The program will not allow you to go beyond a depth of 50.

3. To make reading the output easier, when you exit the program, the output that you had on the screen is written to a file called out.txt. By opening out.txt in notepad, you can review the results without having to worry about them disappearing on the screen. Note that you can't open out.txt until you exit the program. out.txt will be in the same folder as the code is.

The new version C code is below the asterisks. Follow the directions for compiling etc., found in the earlier threads.

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

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

int main()
{
int i, j,  temp1, temp2, temp3, temp4, a1, a2, a3, a4, a;
int drawCount, hit, results, bound = 20;
FILE *in, *out;
int drawArray[50], knfArray[10];

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);
       }

       out = fopen("out.txt", "w");
       if(in == NULL)
       {
          printf("error in opening out.txt\n");
          getch();
          exit(0);
       }
inData:
       printf("Enter the number of past draws to be analyzed.\n"); 
       printf("Start by choosing a number between 1 and 50.\n");
       printf("You might want to start with 20\n");
       scanf("%d", &bound);
       if(bound <=0 || bound > 50)
       {
          printf("The draw depth must be between 1 and 50\n");
          goto inData;     
       } 

       /*
       ** Zero array
       */
       for(i = 0; i < 10; i++)
       {
          knfArray[i] = 0; 
       }
     
       /*
       ** Get the past  draws into memory and then
       ** loop through the draws and see if
       ** there's a key number set for these draws
       */
       i = 0;
       while(!feof(in) && i < bound)
       {
           fscanf(in, "%d", &a);
           drawArray[i] = a;
           i++;
           drawCount++;         
       }
       drawCount = i;

       results = 0;
       printf("***ABC SEGMENT***\n");     
       fprintf(out, "***ABC SEGMENT***\n");     
startABC:
       for(i = 0; i < 210; i++)
       {     hit = 0;
             /*
             ** Peel off the digits from the key number set
             */
             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++)
             {
                /*
                ** Peel off the digits from this draw
                */
                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);
             
                /*
                ** Check to see if at least one digit matches one
                ** in the key set
                */
             
                if((a1 == temp1 || a1 == temp2 || a1 == temp3 || a1 == temp4)
                  ||(a2 == temp1 || a2 == temp2 || a2 == temp3 || a2 == temp4)
                  ||(a3 == temp1 || a3 == temp2 || a3 == temp3 || a3 == temp4))
               {
                  /*
                  ** Bump the match count when a match occurs
                  */
                  hit++;
               } 
                         
             }
         
           
             /*
             ** If the at least one number
             ** in the key number set matched
             ** for all draws, print out the key number set
             */
             if(hit >= drawCount)
             {
                printf("Key Number Set -> %i-%i-%i-%i\n",
                        temp1,  temp2, temp3, temp4);
                fprintf(out, "Key Number Set -> %i-%i-%i-%i\n",
                        temp1,  temp2, temp3, temp4);
                knfArray[temp1]++;       
                knfArray[temp2]++;       
                knfArray[temp3]++;       
                knfArray[temp4]++;       
                     
                /*
                ** Signal that a key number set was found
                */
                results = 1;
             }
             
               

       }


       /*
       ** If no key number set was found, drop the last draw
       ** and search again
       */
       if(results == 0)
       {
            drawCount = drawCount - 1;
            goto startABC;
       }

       /*
       ** Tell the user how many reductions it took
       ** to find a key number set.
       */
       printf("Final draw count used to find key number set was %i\n", drawCount);

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

       results = 0;

       printf("***ABD SEGMENT***\n");     
       fprintf(out, "***ABD SEGMENT***\n");     
startABD:
       for(i = 0; i < 210; i++)
       {     hit = 0;
             /*
             ** Peel off the digits from the key number set
             */
             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++)
             {
                /*
                ** Peel off the digits from this draw
                */
                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);
             
                /*
                ** Check to see if at least one digit matches one
                ** in the key set
                */
             
                if((a1 == temp1 || a1 == temp2 || a1 == temp3 || a1 == temp4)
                  ||(a2 == temp1 || a2 == temp2 || a2 == temp3 || a2 == temp4)
                  ||(a4 == temp1 || a4 == temp2 || a4 == temp3 || a4 == temp4))
               {
                  /*
                  ** Bump the match count when a match occurs
                  */
                  hit++;
               } 
                         
             }
         
           
             /*
             ** If the at least one number
             ** in the key number set matched
             ** for all draws, print out the key number set
             */
             if(hit >= drawCount)
             {
                printf("Key Number Set -> %i-%i-%i-%i\n",
                        temp1,  temp2, temp3, temp4);
                fprintf(out, "Key Number Set -> %i-%i-%i-%i\n",
                        temp1,  temp2, temp3, temp4);
                knfArray[temp1]++;       
                knfArray[temp2]++;       
                knfArray[temp3]++;       
                knfArray[temp4]++;       
                     
                /*
                ** Signal that a key number set was found
                */
                results = 1;
             }
             
               

       }


       /*
       ** If no key number set was found, drop the last draw
       ** and search again
       */
       if(results == 0)
       {
            drawCount = drawCount - 1;
            goto startABD;
       }

       /*
       ** Tell the user how many reductions it took
       ** to find a key number set.
       */
       printf("Final draw count used to find key number set was %i\n", drawCount);
   
       /*
       **Now do segment ACD
       */


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

       results = 0;
       

       printf("***ACD SEGMENT***\n");     
       fprintf(out, "***ACD SEGMENT***\n");     
startACD:
       for(i = 0; i < 210; i++)
       {     hit = 0;
             /*
             ** Peel off the digits from the key number set
             */
             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++)
             {
                /*
                ** Peel off the digits from this draw
                */
                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);
             
                /*
                ** Check to see if at least one digit matches one
                ** in the key set
                */
             
                if((a1 == temp1 || a1 == temp2 || a1 == temp3 || a1 == temp4)
                  ||(a3 == temp1 || a3 == temp2 || a3 == temp3 || a3 == temp4)
                  ||(a4 == temp1 || a4 == temp2 || a4 == temp3 || a4 == temp4))
               {
                  /*
                  ** Bump the match count when a match occurs
                  */
                  hit++;
               } 
                         
             }
         
           
             /*
             ** If the at least one number
             ** in the key number set matched
             ** for all draws, print out the key number set
             */
             if(hit >= drawCount)
             {
                printf("Key Number Set -> %i-%i-%i-%i\n",
                        temp1,  temp2, temp3, temp4);
                fprintf(out, "Key Number Set -> %i-%i-%i-%i\n",
                        temp1,  temp2, temp3, temp4);
                knfArray[temp1]++;       
                knfArray[temp2]++;       
                knfArray[temp3]++;       
                knfArray[temp4]++;       
                     
                /*
                ** Signal that a key number set was found
                */
                results = 1;
             }
             
               

       }


       /*
       ** If no key number set was found, drop the last draw
       ** and search again
       */
       if(results == 0)
       {
            drawCount = drawCount - 1;
            goto startACD;
       }

       /*
       ** Tell the user how many reductions it took
       ** to find a key number set.
       */
       printf("Final draw count used to find key number set was %i\n", drawCount);


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

       results = 0;
     

       printf("***BCD SEGMENT***\n");     
       fprintf(out, "***BCD SEGMENT***\n");     
startBCD:
       for(i = 0; i < 210; i++)
       {     hit = 0;
             /*
             ** Peel off the digits from the key number set
             */
             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++)
             {
                /*
                ** Peel off the digits from this draw
                */
                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);
             
                /*
                ** Check to see if at least one digit matches one
                ** in the key set
                */
             
                if((a2 == temp1 || a2 == temp2 || a2 == temp3 || a2 == temp4)
                  ||(a3 == temp1 || a3 == temp2 || a3 == temp3 || a3 == temp4)
                  ||(a4 == temp1 || a4 == temp2 || a4 == temp3 || a4 == temp4))
               {
                  /*
                  ** Bump the match count when a match occurs
                  */
                  hit++;
               } 
                         
             }
         
           
             /*
             ** If the at least one number
             ** in the key number set matched
             ** for all draws, print out the key number set
             */
             if(hit >= drawCount)
             {
                printf("Key Number Set -> %i-%i-%i-%i\n",
                        temp1,  temp2, temp3, temp4);
                fprintf(out, "Key Number Set -> %i-%i-%i-%i\n",
                        temp1,  temp2, temp3, temp4);
                knfArray[temp1]++;       
                knfArray[temp2]++;       
                knfArray[temp3]++;       
                knfArray[temp4]++;       
                     
                /*
                ** Signal that a key number set was found
                */
                results = 1;
             }
             
               

       }


       /*
       ** If no key number set was found, drop the last draw
       ** and search again
       */
       if(results == 0)
       {
            drawCount = drawCount - 1;
            goto startBCD;
       }

       /*
       ** Tell the user how many reductions it took
       ** to find a key number set.
       */
       printf("Final draw count used to find key number set was %i\n", drawCount);
       printf("***Key Number Frequency***\n");
       fprintf(out, "***Key Number Frequency***\n");
       for(i = 0; i < 10; i++)
       {
          printf("%i\t%i\n", i, knfArray[i]); 
          fprintf(out, "%i\t%i\n", i, knfArray[i]); 
       }

       printf("Enter any key to exit\n");
       getch();




       close(in);


}