Advertisement
Guest User

Day 15

a guest
Dec 15th, 2017
107
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. long int ga,gb;
  3. void init_gens(){
  4.     ga=703;
  5.     gb=516;
  6. }
  7.  
  8. long int update_ga(){
  9.     ga=(ga*16807)%2147483647;
  10.     return ga;
  11. }
  12.  
  13. long int update_gb(){
  14.     gb=(gb*48271)%2147483647;
  15.     return gb;
  16. }
  17.  
  18. long int update_ga2(){
  19.     do{
  20.         update_ga();
  21.     }while((ga%4)!=0);
  22.     return ga;
  23. }
  24.  
  25. long int update_gb2(){
  26.     do{
  27.         update_gb();
  28.     }while((gb%8)!=0);
  29.     return gb;
  30. }
  31.  
  32. int compare_gens(long int (*ua)(), long int (*ub)()){
  33.     long int a=(*ua)();
  34.     long int b=(*ub)();
  35.     return (a&0xFFFF)==(b&0xFFFF);
  36. }
  37.  
  38. int main(){
  39.     init_gens();
  40.     int count = 0;
  41.     for(int i=0;i<40000000;i++)
  42.         count+=compare_gens(&update_ga,&update_gb);
  43.     printf("%d\n", count);
  44.     init_gens();
  45.     count=0;
  46.     for(int i=0;i<5000000;i++)
  47.         count+=compare_gens(&update_ga2, &update_gb2);
  48.     printf("%d\n", count);
  49.     return 0;
  50. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement