C code For Generating Key Numbers For The P3


SUBMITTED BY: Guest

DATE: March 11, 2014, 11:55 p.m.

FORMAT: Text only

SIZE: 6.1 kB

HITS: 1252

  1. C code For Generating Key Numbers For The P3
  2. Hello:
  3. A few members have asked me for the code I used to create keyNumberFinderP3.
  4. Todd suggested pasting it into a blog, and I'm going to do this here.
  5. First a few requirements:
  6. 1. This code is ANSI C and should be compiled into a console executable.
  7. 2. Copy the code, which starts below the asterisks, into your compiler's editor and save as keyNumberFinderP3.c
  8. 3. Once the code has been compiled into an executable move it to a working directory, where you'll have to also create a text draw file consisting of 20 past draws. One draw on a line, no spaces or delimiters. Latest draw first and oldest draw last. This file should be called drawsP3.txt
  9. 4. To run the program click on the keyNumberFinderP3.exe icon. You'll see the results come up in a DOS window.
  10. 5. keyNumberFinderP3.exe may generate more than one set of key numbers. In such a case, pick one set of 4 and stay with that set.
  11. 6. Key numbers are only good for 5 days. After 5 days, update drawsP3.txt. Don't worry about having more than 20 draws in the past draw file, the program only looks at the latest 20.
  12. Good luck and please share your results and methods.
  13. jayemmar
  14. *****************************************************************************
  15. #include <math.h>
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. int main()
  19. {
  20. int i, j, temp1, temp2, temp3, temp4, a1, a2, a3, a4, a;
  21. int drawCount, hit, results;
  22. FILE *in;
  23. int drawArray[20];
  24. int arrayOfFours[210] =
  25. {123,124,125,126,127,128,129,134,135,136,137,138,139,
  26. 145,146,147,148,149,156,157,158,159,167,168,169,178,
  27. 179,189,234,235,236,237,238,239,245,246,247,248,249,
  28. 256,257,258,259,267,268,269,278,279,289,345,346,347,
  29. 348,349,356,357,358,359,367,368,369,378,379,389,456,
  30. 457,458,459,467,468,469,478,479,489,567,568,569,578,
  31. 579,589,678,679,689,789,1234,1235,1236,1237,1238,1239,1245,
  32. 1246,1247,1248,1249,1256,1257,1258,1259,1267,1268,1269,1278,1279,
  33. 1289,1345,1346,1347,1348,1349,1356,1357,1358,1359,1367,1368,1369,
  34. 1378,1379,1389,1456,1457,1458,1459,1467,1468,1469,1478,1479,1489,
  35. 1567,1568,1569,1578,1579,1589,1678,1679,1689,1789,2345,2346,2347,
  36. 2348,2349,2356,2357,2358,2359,2367,2368,2369,2378,2379,2389,2456,
  37. 2457,2458,2459,2467,2468,2469,2478,2479,2489,2567,2568,2569,2578,
  38. 2579,2589,2678,2679,2689,2789,3456,3457,3458,3459,3467,3468,3469,
  39. 3478,3479,3489,3567,3568,3569,3578,3579,3589,3678,3679,3689,3789,
  40. 4567,4568,4569,4578,4579,4589,4678,4679,4689,4789,5678,5679,5689,
  41. 5789,6789};
  42. /*
  43. **Open files
  44. */
  45. in = fopen("drawsP3.txt", "r");
  46. if(in == NULL)
  47. {
  48. printf("error in opening drawsP3.txt\n");
  49. getch();
  50. exit(0);
  51. }
  52. /*
  53. ** Get the past 20 draws into memory and then
  54. ** loop through the first 20 draws and see if
  55. ** there's a key number set for these draws
  56. */
  57. i = 0;
  58. while(!feof(in) && i < 20)
  59. {
  60. fscanf(in, "%d", &a);
  61. drawArray[i] = a;
  62. i++;
  63. drawCount++;
  64. }
  65. drawCount = i;
  66. results = 0;
  67. start:
  68. for(i = 0; i < 210; i++)
  69. { hit = 0;
  70. /*
  71. ** Peel off the digits from the key number set
  72. */
  73. temp1 = arrayOfFours[i]/1000;
  74. temp2 = (arrayOfFours[i] - 1000*temp1)/100;
  75. temp3= (arrayOfFours[i] - 1000*temp1 - 100*temp2)/10;
  76. temp4 = (arrayOfFours[i] - 1000*temp1 - 100*temp2 - 10*temp3);
  77. for(j = 0; j < drawCount; j++)
  78. {
  79. /*
  80. ** Peel off the digits from this draw
  81. */
  82. a = drawArray[j];
  83. a1 = a/100;
  84. a2 = (a - 100*a1)/10;
  85. a3= (a - 100*a1 - 10*a2);
  86. /*
  87. ** Check to see if at least one digit matches one
  88. ** in the key set
  89. */
  90. if((a1 == temp1 || a1 == temp2 || a1 == temp3 || a1 == temp4)
  91. ||(a2 == temp1 || a2 == temp2 || a2 == temp3 || a2 == temp4)
  92. ||(a3 == temp1 || a3 == temp2 || a3 == temp3 || a3 == temp4))
  93. {
  94. /*
  95. ** Bump the match count when a match occurs
  96. */
  97. hit++;
  98. }
  99. }
  100. /*
  101. ** If the at least one number
  102. ** in the key number set matched
  103. ** for all draws, print out the key number set
  104. */
  105. if(hit == drawCount)
  106. {
  107. printf("Key Number Set -> %i-%i-%i-%i\n",
  108. temp1, temp2, temp3, temp4);
  109. /*
  110. ** Signal that a key number set was found
  111. */
  112. results = 1;
  113. }
  114. }
  115. /*
  116. ** If no key number set was found, drop the last draw
  117. ** and search again
  118. */
  119. if(results == 0)
  120. {
  121. drawCount = drawCount - 1;
  122. goto start;
  123. }
  124. /*
  125. ** Tell the user how many reductions it took
  126. ** to find a key number set.
  127. */
  128. printf("Final draw count used to find key number set was %i\n", drawCount);
  129. printf("Enter any key to exit\n");
  130. getch();
  131. close(in);
  132. }

comments powered by Disqus