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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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
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]
Transcribed Image 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]
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education