Advertisement
Guest User

Day 15 Redux

a guest
Dec 15th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAX 2147483647
  3. #define GENUP(GEN,AMT)                      \
  4.     long update_ ## GEN (){                 \
  5.         GEN=(GEN*AMT)%MAX;return GEN;}
  6.  
  7. #define GENUP2(GEN, MODF)                               \
  8.     long update_ ## GEN ## 2 (){                        \
  9.         do{update_ ## GEN ();}while((GEN%MODF)!=0);     \
  10.         return GEN;}
  11.  
  12. long ga,gb;
  13.  
  14. GENUP(ga, 16807)
  15. GENUP(gb, 48271)
  16. GENUP2(ga, 4)
  17. GENUP2(gb, 8)
  18.  
  19. int compare_gens(long (*ua)(), long (*ub)()){
  20.     long int a=(*ua)();
  21.     long int b=(*ub)();
  22.     return (a&0xFFFF)==(b&0xFFFF);
  23. }
  24.  
  25. int judge(int iters, long (*ua)(), long (*ub)()){
  26.     ga=703;gb=516;
  27.     int count = 0;
  28.     for(int i=0;i<iters;i++)
  29.         count+=compare_gens(ua, ub);
  30.     return count;
  31. }
  32.  
  33. int main(){
  34.     printf("%d\n", judge(40000000, &update_ga, &update_gb));
  35.     printf("%d\n", judge(5000000, &update_ga2, &update_gb2));
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement