meditor

Generalized Collatz conjecture

Sep 15th, 2019
156
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //----------------------------------------------------------------------------------------------
  2. // Meditor Digital Strategies since 1989.      
  3. // www.meditor.hu * meditor@meditor.hu          
  4. // This file : CVc.c                            
  5. // Created by: Végvári Lajos                    
  6. // Date      : 2019-sep-15 + 08:06:51          
  7. //----------------------------------------------------------------------------------------------
  8. // >> Sol omnibus lucet                        
  9. //----------------------------------------------------------------------------------------------
  10.  
  11. // C code for generalized Collatz conjecture
  12. // Conjecture generalized and code made by Lajos Végvári (c) 2019.
  13.  
  14. #define     MAX_EXPONENT   5
  15. #define     MAX_NUMBER  5000
  16. #define     MAX_ITER    5000
  17.  
  18. #include    <stdio.h>
  19. #include    <stdlib.h>
  20.  
  21. //----------------------------------------------------------------------------------------------
  22. //----------------------------------------------------------------------------------------------
  23.  
  24.  
  25. int main(int argc, char *argv[])
  26.     {unsigned int   k,exponent,divider;
  27.      unsigned int   number,iter;
  28.      int            result;
  29.      unsigned int   good_cnt, bad_cnt;
  30.  
  31.      unsigned int   add;
  32.  
  33.      printf("\n ** Generalized Collatz conjecture from Lajos Végvári. (c) 2019.\n\n");
  34.      k=0;while(k<MAX_EXPONENT)
  35.      {exponent=(2*k)+1;divider=1<<exponent;
  36.       printf("  > Process with:: EXP: %6d DIV %6d\n",exponent,divider);
  37.  
  38.       good_cnt=bad_cnt=0;
  39.       number=1;while(number<MAX_NUMBER)     // try with 1....(MAX_NUMBER-1)
  40.       {result=number;
  41.  
  42.        iter=0;while(iter<MAX_ITER)          // max length of sequence
  43.        {
  44.         if(!(result%divider)){result/=divider;}
  45.         else                 {add=divider-(result%divider);result*=(divider+1);result+=add;}
  46.  
  47.         if(result==1)break;
  48.         iter++;
  49.        }
  50.  
  51.        if(iter<MAX_ITER){good_cnt++;}
  52.        else{printf("  > Bad sequence:: NUM: %8d RES: %9d\n",number,result);bad_cnt++;}
  53.        number++;
  54.       }
  55.  
  56.       printf("  > Result:: good: %8d bad: %8d\n\n",good_cnt,bad_cnt);
  57.  
  58.       k++;
  59.      }
  60.  
  61.      printf("\n ** Sol omnibus lucet.\n\n");
  62.  
  63.  
  64.      getchar();
  65.      return(0);
  66.     }
  67.  
  68.  
  69. //----------------------------------------------------------------------------------------------
  70. // End of file.                                
  71. //----------------------------------------------------------------------------------------------
RAW Paste Data