Seventeen

Today it is the first day of July in the year 2017. On this day there is a point in time which can be represented as 1.7.2017, 17:17:17.
To celebrate this symbolically speaking 17-heavy day, I created a list of 17 integer sequences which all contain the number 17.
All sequences were generated using a Python program; the source code can be viewed below or downloaded. Because the following list is formatted using LaTex, the program’s plaintext output can also be downloaded.

  1. Prime numbers n.
    \{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, \dots\}
  2. Odd positive integers n whose number of goldbach sums (all possible sums of two primes) of n+1 and n-1 are equal to one another.
    \{5, 7, 15, 17, 19, 23, 25, 35, 75, 117, 177, 207, 225, 237, 321, 393, 453, 495, 555, 567, \dots\}
  3. Positive integers n who are part of a Pythagorean triple excluding 0: n^2=a^2+b^2 with integers a,b>0.
    \{5, 10, 13, 15, 17, 20, 25, 26, 29, 30, 34, 35, 37, 39, 40, 41, 45, 50, 51, 52, \dots\}
  4. Positive integers n where \lfloor (n!)^{\frac{1}{n}} \rfloor is prime
    \{4, 5, 6, 7, 8, 12, 13, 17, 18, 19, 28, 29, 33, 34, 35, 44, 45, 46, 49, 50, \dots\}
  5. Positive integers n with distance 1 to a perfect square.
    \{1, 2, 3, 5, 8, 10, 15, 17, 24, 26, 35, 37, 48, 50, 63, 65, 80, 82, 99, 101, \dots\}
  6. Positive integers n where the number of perfect squares including 0 less than n is prime.
    \{2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 37, 38, 39, \dots\}
  7. Prime numbers n where either n-2 or n+2 (exclusive) are prime.
    \{3, 7, 11, 13, 17, 19, 29, 31, 41, 43, 59, 61, 71, 73, 101, 103, 107, 109, 137, 139, \dots\}
  8. Positive integers n whose three-dimensional vector’s (n, n, n) floored length is prime, \lfloor \sqrt{3 \cdot n^2} \rfloor is prime.
    \{2, 3, 8, 10, 11, 17, 18, 24, 25, 31, 39, 41, 46, 48, 60, 62, 63, 76, 91, 100, \dots\}
  9. Positive integers n who are the sum of a perfect square and a perfect cube (excluding 0).
    \{2, 5, 9, 10, 12, 17, 24, 26, 28, 31, 33, 36, 37, 43, 44, 50, 52, 57, 63, 65, \dots\}
  10. Positive integers n whose decimal digit sum is the cube of a prime.
    \{8, 17, 26, 35, 44, 53, 62, 71, 80, 107, 116, 125, 134, 143, 152, 161, 170, 206, 215, 224, \dots\}
  11. Positive integers n for which \text{decimal\_digitsum}(n)+n is a perfect square.
    \{2, 8, 17, 27, 38, 72, 86, 135, 161, 179, 216, 245, 275, 315, 347, 432, 467, 521, 558, 614, \dots\}
  12. Prime numbers n for which \text{decimal\_digitsum}(n^4) is prime.
    \{2, 5, 7, 17, 23, 41, 47, 53, 67, 73, 97, 103, 113, 151, 157, 163, 173, 179, 197, 199, \dots\}
  13. Positive integers n where decimal_digitsum(2 \cdot n) is a substring of n.
    \{9, 17, 25, 52, 58, 66, 71, 85, 90, 104, 107, 115, 118, 123, 137, 142, 151, 156, 165, 170, \dots\}
  14. Positive integers n whose decimal reverse is prime.
    \{2, 3, 5, 7, 11, 13, 14, 16, 17, 20, 30, 31, 32, 34, 35, 37, 38, 50, 70, 71, \dots\}
  15. Positive integers n who are a decimal substring of n^n.
    \{1, 5, 6, 9, 10, 11, 16, 17, 19, 21, 24, 25, 28, 31, 32, 33, 35, 36, 37, 39, \dots\}
  16. Positive integers n whose binary expansion has a prime number of 1‘s.
    \{3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 17, 18, 19, 20, 21, 22, 24, 25, 26, 28, \dots\}
  17. Positive integers n whose 7-segment representation uses a prime number of segments.
    \{1, 2, 3, 5, 7, 8, 12, 13, 15, 17, 20, 21, 26, 29, 30, 31, 36, 39, 47, 48, \dots\}

# Python 2.7.7 Code
# Jonathan Frech, 29th, 30th  of June 2017

Continue reading

Tau Day MMXVII

Today it is June the 28th which means that it is \tau day!
The irrational and transcendental constant \tau is what defines \pi = \frac{\tau}{2}, which obviously makes it an important constant. To celebrate this day, I created a C program which calculates \tau by randomly creating 9-dimensional points inside the 9-dimensional hypercube and testing if they are inside the 9-dimensional hypersphere with its center located at (0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5).

Today’s \tau time is 3:18:53 as \tau = 6.2831853 \dots. As one does not know if the time is specified as ante or post meridiem, there are actually two perfectly acceptable \tau times.

            ;b$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$b
        h$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ 
     .$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$+ 
    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$  
  ,$$$$$$$$$kn}~I"`($$$$$$$x````````````````   
 )$$$m             $$$$$$$$                    
+$$c              q$$$$$$$>                    
$$                $$$$$$$$                     
                 $$$$$$$$.                     
                '$$$$$$$$                      
                $$$$$$$$                       
               ?$$$$$$$a                       
               $$$$$$$$                        
              Q$$$$$$$f                        
              $$$$$$$$                         
             $$$$$$$$i                         
             $$$$$$$$                          
            $$$$$$$$;                          
            $$$$$$$$                           
           J$$$$$$$w                           
           $$$$$$$$;             $$~           
           $$$$$$$$             $$$            
          '$$$$$$$$C          "$$$             
           $$$$$$$$$w       '$$$$              
           $$$$$$$$$$$$$$$$$$$$B               
            $$$$$$$$$$$$$$$$$$.                
             $$$$$$$$$$$$$$$'                  
                8$$$$$$$q                      

The formula used for calculating \tau is derived from a 9-dimensional hypersphere’s hypervolume formula V = \frac{32 \cdot \pi^4}{945} \cdot R^9 (see this Wikipedia article).
V = \frac{2^5 \cdot \tau^4 \cdot R^9}{945 \cdot 2^4} = \frac{2 \cdot R^9}{945} \cdot \tau^4
\tau^4 = \frac{V \cdot 945}{2 \cdot R^9}; R = 0.5
\tau^4 = \frac{V \cdot 945 \cdot 2^9}{2}
\tau = \sqrt[4]{V \cdot 241920}

The constant gets calculated to \tau^* = 6.293700. The real value is approximately \tau = 6.283185 \dots, which makes the percent error \left|\frac{\tau^*-\tau}{\tau}\right| = \left|\frac{6.293700-6.283185}{6.283185}\right| = 0.001673514 = 0.167\%.
Thereby this C program’s approximation is not too far off. The source code is listed below and can also be downloaded here. Instructions on how to compile it using GCC can be seen below or in the source code.

gcc tau.c -o tau -lm; ./tau
tau = 6.293700

Resources worth checking out regarding \tau are The Tau Manifesto and 2 Pi or Not 2 Pi?. I wish everybody a happy \tau day.


// C Code
// Jonathan Frech, 27th of June 2017

Continue reading

Mandelbrot Set ASCII Viewer

The Mandelbrot Set is the set of all complex points which, when one iteratively and infinitely applies the function f_c(z)=z^2+c, converge to a value. This simple rule results in stunning complexity and beauty.
Many Mandelbrot Set animations use regularly colored pixels to represent the number of iterations needed at the fractal’s edges to escape converging. Yet this mathematical object can also be represented as ASCII characters — similar to what I did in my Curses Cam post. The characters are chosen according to their opaqueness. A full stop (‘.’) looks lighter than a dollar sign (‘$’), so they represent a smaller or larger number of iterations needed. The order of characters used is taken from this post by Paul Borke.
As there are only 70 characters used, each frame is being rendered twice to determine the minimum number of iterations needed by every point in that frame. Thereby the full visual character range is used.

The characters shown below represent a Mandelbrot Set still. To see the zoom in action, either run the program (listed below) or take a look at this Mandelbrot Set ASCII journey.

      ..................''''''''``"">>II``''''......                          
    ..................''''''''``^^,,ii::^^``''''......                        
  ..................''''''''``^^::ww$$++,,````''''......                      
................''''''''``^^^^""::$$$$$$::""^^``''''......                    
..............''''''````""{{;;XX$$$$$$$$uuUU,,,,""''......                    
............''''``````^^,,rr$$$$$$$$$$$$$$$$<<$$--``........                  
........''``````````^^""LL$$$$$$$$$$$$$$$$$$$$__""``''......                  
..''''''^^!!"""",,""""::__$$$$$$$$$$$$$$$$$$$$$$ll""''........                
''''````^^::__IIYYii::ll$$$$$$$$$$$$$$$$$$$$$$$$pp^^''........                
''``````"";;[[$$$$$$++__$$$$$$$$$$$$$$$$$$$$$$$$$$^^''''......                
``^^^^,,;;>>$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ww``''''......                
"",,,,II$$nn$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$""``''''......                
"",,,,II$$nn$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$""``''''......                
``^^^^,,;;>>$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ww``''''......                
''``````"";;[[$$$$$$++__$$$$$$$$$$$$$$$$$$$$$$$$$$^^''''......                
''''````^^::__IIYYii::ll$$$$$$$$$$$$$$$$$$$$$$$$pp^^''........                
..''''''^^!!"""",,""""::__$$$$$$$$$$$$$$$$$$$$$$ll""''........                
........''``````````^^""LL$$$$$$$$$$$$$$$$$$$$__""``''......                  
............''''``````^^,,rr$$$$$$$$$$$$$$$$<<$$--``........                  
..............''''''````""{{;;XX$$$$$$$$uuUU,,,,""''......                    
................''''''''``^^^^""::$$$$$$::""^^``''''......                    
  ..................''''''''``^^::ww$$++,,````''''......                      
    ..................''''''''``^^,,ii::^^``''''......

The fractal viewer is written in Python 2.7 and works by determining the terminal’s size and then printing a string of according size. This creates the illusion of a moving image, as the terminal will hopefully always perfectly scroll so that only one frame is visible at a time.
In the code’s first non-comment line one can change the complex point at the image’s center, (really, its conjugate, which is partially irrelevant as the set is symmetric along the real axis) the initial zoom value (complex distance above the image’s center), the zoom factor (the factor by which the zoom value gets multiplied after a frame), the total number of frames (-1 means there is no upper limit), the delay between frames (in seconds, can be floating-point) and the color characters used.

The program’s source code may not be particularly easy to read, yet it does its job and only requires seven non-comment lines! The code is shown below, though the .py file can also be downloaded.
To achieve the JavaScript animation linked to above, I wrote a simple Python converter which takes in the fractal renderer’s output and it spits out an HTML page. This converter’s code is not listed, though the .py file can be downloaded. Instructions on how to use the converter can be seen in its source code.


# Python 2.7 Code; Jonathan Frech, 15th and 16th of June 2017
P,Z,F,N,D,K=-.707+.353j,3,.9,-1,.1," .'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$"
import os,time,sys;H,W,S,n=map(int,os.popen("stty size").read().split())+[sys.stdout,0];W/=2
def C(c):
	global m;z,i=0j,-1
	while abs(z)<=2 and i<len(K)-1+M:z,i=z*z+c,i+1
	m=min(m,i);return K[i-M]*2
while n<N or N==-1:h=Z*2.;w=h*W/H;R=lambda:"\n\n"*(n!=0)+"\n".join("".join(C(P-complex(w/2-w*x/W,h/2-h*y/H))for x in range(W))for y in range(H));M,m=0,len(K);R();M=max(M,m);S.write(R());S.flush();Z,n=Z*F,n+1;time.sleep(D)