Fractran interpreter def fractran(n, prog, giveup=1000): John Conway, who was quite a character among mathematicians, is best known for The Game of Life, not to be confused with the family board game...



Fractran interpreter

def fractran(n, prog, giveup=1000):


John Conway, who was quite a character among mathematicians, is best known for The Game of Life, not to be confused with the family board game sharing the same name. That achievement eclipsed basically all other wacky and original creations of Conway, so in the name of fairness, we ought to

give his less appreciated creations an occasional turn in the flashing lights of the red carpet fame.


This lab has you write an interpreter for the simple esoteric programming language called FRACTRAN, named as a pun of the word “fraction” and the FORTRAN programming language. (Things used to be all in uppercase back in when real scientists wore horn-rimmed glasses and their cars were equipped with tail fins, with occasional dollar signs interspersed as separators to keep the pampered prices of the military-industrial complex happy.) A program written in such mysterious and hard-to-decipher form consists of nothing but a list of positive integer fractions, in this problem given as tuples of the numerator and the denominator. Of course, you are not merely allowed but encouraged to use the Fraction data type of the Python fractions module to simplify the computations inside your function.


Given a positive integer n as its start state, the next state is the product n*f for the first fraction listed in prog for which n*f is an exact integer. That integer then becomes the new state for the next round. Once n*f is not an integer for any of the fractions f listed in prog, the execution

terminates. Your function should compute and return the sequence of integers produced by the given FRACTRAN program, with a forced termina... sorry, forced halting (after all, Conway was British) taking place after giveup steps, if the execution has not halted by then.


prog<br>giveup |Expected result<br>[(17, 91), (78, 85), (19, 20<br>51), (23, 38), (29, 33),<br>(77, 29), (95, 23), (77,<br>19), (1, 17); (11, 13);<br>(13, 11), (15, 2), (1,<br>7), (55, 1)]<br>[2, 15, 825, 725, 1925,<br>2275, 425, 390, 330,<br>290, 770, 910, 170,<br>156, 132, 116, 308,<br>364, 68, 4, 30]<br>2<br>(same as above)<br>20<br>[9, 495, 435, 1155,<br>1015, 2695, 3185, 595,<br>546, 102, 38, 23, 95,<br>385, 455, 85, 78, 66,<br>58, 154, 182]<br>

Extracted text: prog giveup |Expected result [(17, 91), (78, 85), (19, 20 51), (23, 38), (29, 33), (77, 29), (95, 23), (77, 19), (1, 17); (11, 13); (13, 11), (15, 2), (1, 7), (55, 1)] [2, 15, 825, 725, 1925, 2275, 425, 390, 330, 290, 770, 910, 170, 156, 132, 116, 308, 364, 68, 4, 30] 2 (same as above) 20 [9, 495, 435, 1155, 1015, 2695, 3185, 595, 546, 102, 38, 23, 95, 385, 455, 85, 78, 66, 58, 154, 182]
Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here