Skip to content

Latest commit

 

History

History
132 lines (129 loc) · 9.25 KB

README.md

File metadata and controls

132 lines (129 loc) · 9.25 KB

Usage

./prime-plot [options]

Options

  --help              Displays this information
  --action=<action>   Specify the action the program will execute.
                      These are the supported values for <action>:
                        generate
                            Generate all primes up to the specified limit in
                            the specified base and output them.
                        last-digit-ascii-art
                            Check all primes up to the specified limit in the
                            specified base for their last digit and output
                            the number of combinations for consecutive primes
                            in an ascii art table. The left column will
                            contain the first value of the combination (the
                            'from' number), the top row will contain the
                            second value (the 'to' number). Note that all
                            information the table contains will be in base
                            10.
                        last-digit-csv
                            Like last-digit-ascii-art, but uses comma
                            separated values for output and will not contain
                            any headers.
                        last-digit-csv-with-headers
                            Like last-digit-csv, but output will include
                            headers embedded into the 'useful' output.
                        diagonal-averages
                            Output the averages of all diagonals, from bottom
                            left to top right, of the table generated by any
                            last-digit-* action. E.g. when --base=3, the rows
                            (with the 'from' numbers) are from 0 to 2, the
                            columns (with the 'to' numbers) have the same
                            range. The first number output by this action will
                            then be the 2-->0 number. The second will be the
                            average of the 2-->1 and 1-->0 numbers. The third
                            will be the average of the 2-->2, 1-->1 and 0-->0
                            numbers and so on. Eventually, this will lead to
                            2*base-1 output numbers.
                        plot-diagonal-averages
                            Uses the output of diagonal-averages (by
                            internally calling) it and plots it in a cartesian
                            coordinate system with the index of the diagonal
                            average on the x-axis and the value of the
                            diagonal average on the y-axis. The size of the
                            coordinate system can be changed using the
                            --terminal-size option. If that option is not
                            given, and you are on a Unix operating system, the
                            current terminal size is read using platform-
                            dependent commands so that the coordinate system
                            will fit the terminal exactly. Note that your
                            terminal has to support Unicode characters for
                            correctly showing the output of this action,
                            because the representation of individual pixels is
                            realized using Braille characters.
                      This option is required.
  --base=<base>[,<alphabet>] Set the base to use for primes during processing.
                      Note that this option will not change the base of the
                      number of combination output by last-digit-* actions.
                      However, it does change the base of primes output by
                      the generate action. The alphabet is optional with a
                      default value of 0123456789, but if it is given, it has
                      to be a string that is 'base' characters long and that
                      contains the alphabet used for outputting numbers. As
                      an example, you may use
                      --base=26,ABCDEFGHIJKLMNOPQRSTUVWXYZ if you want to
                      output the primes in base 26 with letters as numbers.
                      If this option is not given, base 10 with 0123456789 as
                      alphabet is used.
  --limit=<limit>     Set the limit for the number of primes to test (not the
                      primes themselves!). When the value has a K, M, G or T
                      prefix, it will be multiplied by a thousand, a million,
                      a billion or a trillion, respectively. This option is
                      required.
  --output=<file>     Sets the filename of the file used for output. If this
                      option is not given, the standard output is used.
  --prime-input=<file>[,<begin_index>] When a valid file is specified for
                      this option, the primes needed for the desired action
                      will be read from it (for 'generate' as well). If
                      this option is not given, all of the needed primes
                      will be generated again at runtime. When a value for
                      'limit' is specified and the specified input file
                      does not contain all needed primes, the missing ones
                      will be generated as well. The begin index is not
                      necessary for this option (its default value is 0,
                      because the first line is expected to contain 2), but
                      if it is given, it specifies the index of the first
                      prime in the file (zero-based), e.g. the begin index
                      for this option should be 1233 if the first line in
                      the file contains 10061.
  --prime-input-base=<base>[,<alphabet] Expects the same parameters as
                      --base, but controls the base of the primes read from
                      the file specifies by --prime-input. If this option is
                      not given, base 10 with 0123456789 as alphabet is used.
  --row-interval=i,j  Only output every jth row, beginning at row i. The row
                      numbers are zero-based. E.g. when this option's value
                      is 2,3, the program will output the rows #2, #5, #8
                      and so on. The default value for this option is 0,1.
  --column-interval=i,j Works just like --row-interval, just for columns. The
                      default value for this option is 0,1 as well.
  --enable-ascii-art-colors=y/n If this option's value begins with 'n' or '0',
                      and --action=last-digit-ascii-art, the background of
                      the numbers in the table body will be colored. If a
                      value is the highest in the table, it will be colored
                      in bright red, linearly going down to white, i.e. 0.
                      Note that ANSI escape sequences are used to color the
                      background in true color (ISO-8613-3), your terminal
                      may not support this. Recent versions of Xterm, GNOME
                      terminal, KDE's Konsole and the OS X terminal should
                      support this, others may or may not, and Windows's
                      CMD does not at all. When the output is redirected
                      to a file using --output, this option is ignored and
                      no colors are used. By default, this option is disabled.
  --terminal-size=width,height If the application is used on a Unix system
                      and the plot-diagonal-averages action is used, this
                      option is optional, otherwise it is required.
                      This option expects the width and height of the terminal
                      it runs in in a number of simple characters.

Examples

  • ./prime-plot --action=generate --limit=10K
  • ./prime-plot --action=generate --limit=10K --base=26,ABCDEFGHIJKLMNOPQRSTUVWXYZ
  • ./prime-plot --action=generate --limit=1M --output=primes1m.txt
  • ./prime-plot --action=last-digit-ascii-art --limit=100K
  • ./prime-plot --action=last-digit-ascii-art --limit=100K --enable-ascii-art-colors=y --base=16 --row-interval=1,2 --column-interval=1,2
  • ./prime-plot --action=plot-diagonal-averages --prime-input=primes1m.txt --limit=100K
  • ./prime-plot --action=plot-diagonal-averages --prime-input=primes1m.txt --limit=100K --base=128 --row-interval=1,2 --column-interval=1,2

Background

I actually got the idea for this program from this Numberphile video where the amazing Dr. James Grime explains patterns in the last digits of primes. Just for fun, I wanted to take this a step further and explore these patterns in other bases as well. For a non-mathematician like me, the arising patters were very surprising. And because Linux terminals support the entire RGB set, it is possible to plot them with a lot of color! When you have access to a non-Windows machine, you should really try out these examples! For your convenience, I kept the executable file in the bin directory, but of course, if you have the neccessary tools, you can do make clean && make.