From Esolang
Jump to navigation Jump to search

Factor (also known as Factors) is a zero-dimensional, cell-based, imperative programming language invented by User:Bangyen in 2020.

Paradigm(s) Imperative
Designed by Bangyen Pham
Appeared in 2020
Memory system Cell-based
Dimensions Zero-dimensional
Computational class Turing complete
Major implementations Java interpreter
Influenced by Brainfuck
File extension(s) .fact

Language overview

Factor is based on the prime factorization of numbers. Every program is a number, and the instructions of each program are determined by the number's prime factors and their multiplicity. Each factor is a different instruction (based on it's residue modulo 11), and each factor's multiplicity is the number of times the instruction is carried out. The order of the instructions is determined by sorting the factors in ascending order. The different instructions are as follows:

Move right Move left Increment Decrement Output Input Start loop End loop
Z₁₁ Residue 1 2 3 4 5 6 7 8
Brainfuck equivalent > < + - . , [ ]

Left and right refer to moving the pointer, whereas increment and decrement refer to changing the cell designated by the pointer. Loops are started if the current cell value is nonzero, and loops are ended if the current cell is zero. The cells are right unbounded and wrap at 0 and 256. All residue values other than 12345678 should be ignored. All characters other than 0123456789 should be considered comments and ignored.


Hello, World!

This program prints out the words Hello World!:



The Cat program, on the other hand, is represented as the number 310861643. The brainfuck equivalent would be ,[.,], since its prime factorization is 17 * 29 * 71 * 83 * 107. The equivalence is a result of the following congruencies:

Modular Equation Instruction
17 ≡ 6 (mod 11) Input
29 ≡ 7 (mod 11) Start loop
71 ≡ 5 (mod 11) Output
83 ≡ 6 (mod 11) Input
107 ≡ 8 (mod 11) End Loop


A polyglot truth-machine by User:Salpynx.


Brainfuck interpreter

A brainfuck interpreter—original brainfuck code by Daniel B. Cristofani.



Brainfuck to Factor

# Ruby program
require 'prime'

def translate(code)
    res = 1; i = 2; str = '0><+-.,[]'
    for char in code.chars
        while i % 11 != str.index(char) || !i.prime?
            i += 1
       res *= i

Factor to brainfuck

# Ruby program
require 'prime'

def translate(num)
    res = ""; i = 2; str = '0><+-.,[]'
    while num != 1
        while num % i != 0
            i += 1
        num /= i
        res += str[i % 11]

Computational class

The number 11 was chosen because it is the smallest number such that there exists at least 8 (the number of instructions) natural numbers less than and coprime to it. The reason why coprimality is important is because Dirichlet's theorem ensures that there are an infinite number of primes that are congruent to each coprime integer modulo 11. As a result, because Factor is equivalent to Brainfuck, a Turing-complete language, Factor is also Turing complete.

External Resources