Winter MMXVIII

                                         I                                         
                                        ,O;                                        
                                       main(                                       
                                      ){char*                                      
                                     Q,_[]={73                                     
                                    ,44,79,59,2                                    
                                   ,109,97,105,2                                   
                                  ,110,40,41,123,                                  
                                 99,104,97,114,42,                                 
                                81,44,95,91,93,61,2                                
                               ,123,1,48,125,44,42,2                               
                              ,74,59,102,111,114,40,2                              
                             ,81,61,95,44,73,61,79,61,                             
                            48,59,42,81,59,43,43,81,41,                            
                           123,105,102,40,42,81,60,50,41                           
                          ,102,111,114,40,74,61,95,59,42,                          
                         74,59,74,43,43,41,73,60,49,38,38,                         
                        112,114,105,110,116,102,40,34,37,42                        
                       ,99,34,44,52,50,45,79,47,50,45,49,44,                       
                      51,50,41,44,73,43,61,112,114,105,110,2,                      
                     116,102,40,34,37,100,34,44,42,74,41,44,73                     
                    ,62,79,63,73,61,48,44,79,43,61,50,44,112,2,                    
                   117,116,115,40,34,34,41,58,48,44,73,43,43,60,                   
                  49,63,112,114,105,110,116,102,40,34,37,42,99,34                  
                 ,44,52,50,45,79,47,50,44,52,52,41,58,112,117,116,                 
                99,104,97,114,40,52,52,41,44,73,62,79,63,73,61,48,2                
               ,44,79,43,61,50,44,112,117,116,115,40,34,34,41,58,48,               
              59,105,102,40,42,81,62,50,41,73,43,43,60,49,63,112,114,              
             105,110,116,102,40,34,37,42,99,34,44,52,50,45,79,47,50,44             
            ,42,81,41,58,112,117,116,99,104,97,114,40,42,81,41,44,73,62            
           ,79,63,73,61,48,44,79,43,61,50,44,112,117,116,115,40,34,34,41           
          ,58,48,59,125,102,111,114,40,73,61,48,59,73,43,43,60,49,55,59,2          
         ,112,117,116,99,104,97,114,40,52,55,41,41,59,102,111,114,40,73,61         
        ,112,117,116,115,40,34,34,41,59,73,43,43,60,53,59,112,117,116,115,2        
       ,40,34,34,41,41,123,112,114,105,110,116,102,40,34,37,42,99,34,44,51,2       
      ,50,44,52,55,41,59,102,111,114,40,74,61,48,59,74,43,43,60,50,48,59,41,2      
     ,2,112,117,2,116,99,2,2,104,2,97,2,114,2,40,52,2,55,41,2,59,125,2,2,125,2     
    ,2,0},*J;for(Q=_,I=O=0;*Q;++Q){if(*Q<2)for(J=_;*J;J++)I<1&&printf("%*c",42-    
   O/2-1,32),I+=printf("%d",*J),I>O?I=0,O+=2,puts(""):0,I++<1?printf("%*c",42-O/   
  2,44):putchar(44),I>O?I=0,O+=2,puts(""):0;if(*Q>2)I++<1?printf("%*c",42-O/2,*Q)  
 :putchar(*Q),I>O?I=0,O+=2,puts(""):0;}for(I=0;I++<17;putchar(47));for(I=puts(""); 
I++<5;puts("")){printf("%*c",32,47);for(J=0;J++<20;)putchar(47);}}/////////////////
                               /////////////////////                               
                               /////////////////////                               
                               /////////////////////                               
                               /////////////////////                               

Try it online.

Advertisements

Symbolic Closed-Form Fibonacci

Let V := \{(a_j)_{j\in\mathbb{N}}\subset\mathbb{C}|a_n=a_{n-1}+a_{n-2}\forall n>1\} be the two-dimensional complex vector space of sequences adhering to the Fibonacci recurrence relation with basis B := ((0,1,\dots), (1,0,\dots)).
Let furthermore f: V\to V, (a_j)_{j\in\mathbb{N}}\mapsto(a_{j+1})_{j\in\mathbb{N}} be the sequence shift endomorphism represented by the transformation matrix

A := M^B_B(f) = \begin{pmatrix}1&1\\1&0\end{pmatrix}.

By iteratively applying the sequence shift a closed-form solution for the standard Fibonacci sequence follows.

Continue reading

Prime Intirety

Since ancient times humanity knew that there are infinitely many primes — though countable, writing a complete list of every prime is impossible if one intends to finish.
However, in practice one often only considers a minute subset of the naturals to work with and think about. When writing low-level languages like C, one is nearly forced to forget about almost every natural number — the data type u_int_32, for example, is only capable of representing \{\mathbb{N}_0\ni n<2^{32}\}.
Therefore, it is possible to produce a complete list of every prime representable in thirty-two bits using standard bit pattern interpretation — the entirety of the first 203\,280\,221 primes.

Generating said list took about two minutes on a 4GHz Intel Core i7 using an elementary sieve approach written in C compiled with gcc -O2.
All primes are stored in little-endian format and packed densely together, requiring four bytes each.

Using the resulting file, one can quickly index the primes, for example p_{10^7} = 179\,424\,691 = \text{ab1cdb3}_{16} (using zero-based indexing). Since each prime is stored using four bytes, the prime’s index is scaled by a factor of four, resulting in its byte index.

dd status=none ibs=1 count=4 if=primes.bin skip=40000000 | xxd 
00000000: b3cd b10a                                ....

Source code: intirety.c
Prime list: primes.bin (775.5 MiB)