Programming contests

ECN programozó csapatverseny, 2018. május 12.

May 12, 2018 10:15 AM – May 12, 2018 3:15 PM

Run a FRACTRAN Program

One of the most brilliant mathematicians of all time, J. H. Conway at Princeton University, discovered a “Simple Universal Programming Language for Arithmetic”, which he named FRACTRAN.

The idea is deceptively simple but unexpectedly powerful and is based on the next fraction game. There is given a finite list of fractions

f1, f2, …, fk

and a starting integer n. “You repeatedly multiply the integer you have at any stage (initially n) by the earliest fi in the list for which the product is integral. Whenever there is no such fit, the game stops.” (Quotation from T. M. Cover et al. (eds.), Open Problems in Communication and Computation, Springer-Verlag New York Inc., 1987) Thats all.

Here it is the program, i.e. the “game”, which lists… all the prime numbers!

1791, 7885, 1951, 2338, 2933, 7729, 9523, 7719, 117, 1113, 1311, 152, 17, 551

More exactly, if you start with n = 22, then whenever a power of two appears as the value of n, then that is exactly the subsequent prime power of 2:

23, 25, 27, 211, 213, 217, …

Question: How many steps does it take starting with n = 22 to obtain n = 237?

Input Specification

There is no input for this problem.

Output Specification

The output should contain a single integer, the number of steps required.

University of Debrecen; Faculty of Informatics; v. 03/01/2019