Hacker News new | past | comments | ask | show | jobs | submit login

My favorite is this FRACTRAN program: (17/91, 78/85, 19/51, 23/38, 29/33, 77/29, 1/17, 11/13, 13/11, 15/2, 1/7, 55/1) with input 2.

It doesn't quite produce primes directly. It gives a sequence of integers, some of which are powers of 2. Those powers of 2 are 2^2, 2^3, 2^5, 2^7, 2^11, ..., i.e., the sequence of 2 to the power of primes.

For those who have never seen FRACTRAN it is an esoteric programming language invented by John Conway. It is Turing-complete.

Here's how you execute a FRACTRAN program, with input N.

1. Step through the list of fractions in order until you find a fraction f such that fN is an integer or you run out of fractions.

2. If you run out of fractions halt.

3. Output fN.

4. Replace N with fN.

5. Goto step 1.

Wikipedia gives some sample programs and explains in detail how the heck FRACTRAN can compute: https://en.wikipedia.org/wiki/FRACTRAN




Consider applying for YC's W25 batch! Applications are open till Nov 12.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: