📜 ⬆️ ⬇️

Pi in programming languages

March 14 is World Pi Day. Invented in 1989 and officially recognized in 2009, this day is celebrated in many ways, of which the most popular are eating round cakes and discussing things related to the number of pi. It would be strange if there were not a couple of programming languages ​​based on the number Pi or even named in his honor. I will tell about them - it is necessary to support the tradition :-)

1. Pi - Brainfuck dialect


Brainfuck has many dialects for almost all occasions, Pi is among them too. Language commands are written to Pi as irregular digits in random digits as follows.
')
For each command, a digit is selected in which it will be recorded (the bits are ordered in the same way as the commands in the source code). Takes table of correspondence of commands and numbers

< > + — . , [ ]
0 1 2 3 4 5 6 7 8


and in it the command line is shifted by one to the right, starting with the command above the digit that is in the selected digit in the correct number Pi. For example, if the second digit after the decimal point is selected, the correct digit in it is 4, and the correspondence table takes the following form:

< > + — . , [ ]
0 1 2 3 4 5 6 7 8


Now, using the necessary command, we select the corresponding figure and replace it with the correct one in the selected digit. The result of recording a program is a number similar to Pi, but in some places different from it. So, the “Hello, World!” Program, which is written like this on Brainfuck:

++++++[>++++++++++++<-]>.>++++++++++[>++++++++++<-]>+.+++++++..+++.>++++[>++++++
+++++<-]>.<+++[>----<-]>.<<<<<+++[>+++++<-]>.>>.+++.------.--------.>>+.


on Pi is written like this:

3.141592653589793238462623382272502824197169299275107820904924592337816406386238
99262833482534311206728234808621328230264709314460935058223872535941812844111745
00841022019385311055296426229289549302819244388109726652334471204756422337867231
65221231909345628566933460342610454226248213391607264249148273720587036656315582
17288153092396282225439171532436789559536003133023024882044652108412695192151163
94330573703656595909530921261173839326137921051125420742623799227495273538857227
24892227938133011749109833675362442656243086321294946795024737130702479860343702
77453921711629317375838467480846766440513202056822724526351082178577132275778260
91736271767204684409312229532301462492853110307922896892089235450199501120290219
65862034218129813624774731309964518707241349993993372978039951049734732816036348
59504445345544690330263252250825304468003522193158817101


2. Another Pi Language


Unusual even for esoteric languages, this language exists only as a theoretical description. The idea of ​​the language is based on the well-known theory that among Pi you can find any information if you select the correct encoding. In this case, Pi is written in binary representation.

11.
00100100 00111111 01101010 10001000 10000101 10100011 00001000 11010011
00010011 00011001 10001010 00101110 00000011 01110000 01110011 01000100
10100100 00001001 00111000 00100010 00101001 10011111 00110001 11010000
00001000 00101110 11111010 10011000 11101100 01001110 01101100 10001001


The source code of the program on Another Pi Language is a pair of numbers: the index of the bit from which to start reading, and the number of bytes to read. The read bytes are translated into characters with the corresponding ASCII codes, and the resulting text is interpreted as source code in some other language (the language must be specified along with a pair of numbers).

Theoretically, among Pi you can find any sequence of bits of any length, that is, the code of any arbitrarily complex program. This language will even be Turing-complete (because it can perform any task that can be performed in other languages). Another thing is that the complexity of programming on it, he can argue with Malbolge . However, unlike Malbolge, “Hello, World!” Is written on Another Pi Language easily and elegantly:

3 1 HQ9+

To "interpret" this code:

A few more examples of different lengths:

(the last two examples were found using Search Pi )

3. Pi pattern language


Something in between a development tool and a philosophy of creating new programming languages. It is based on the idea of ​​extensibility of the semantics and syntax of programming languages ​​by means of the languages ​​themselves.

4. Bonus :-)


A small gift for Pi Day : Pi Day Challenge 2011 - an annually updated series of puzzles related to Pi number.

Source: https://habr.com/ru/post/115401/


All Articles