Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The code is needed in python only AND must pass the following tests def test_number_number_to_string(): ''' This function runs a number of tests of the

The code is needed in python only

image text in transcribed

AND must pass the following tests

def test_number_number_to_string(): ''' This function runs a number of tests of the number_to_string function. If it works ok, you will just see the output ("all tests passed") at the end when you call this function; if some test fails, there will be an error message. ''' assert number_to_string(1, 1) == '' assert type(number_to_string(1, 1)) == str assert number_to_string(2, 1) == 'R' assert type(number_to_string(2, 1)) == str assert number_to_string(3, 1) == 'RR' assert type(number_to_string(3, 1)) == str assert number_to_string(4, 1) == 'R'*3 assert type(number_to_string(1, 4)) == str assert number_to_string(3,11) == 'LLLRL' assert type(number_to_string(89, 55)) == str assert number_to_string(89, 55) == 'RLRLRLRLR' assert type(number_to_string(8, 111)) == str assert number_to_string(144, 89) == 'RL' * 5 print("all tests passed")

def test_string_to_number(): ''' This function runs a number of tests of the string_to_number function. If it works ok, you will just see the output ("all tests passed") at the end when you call this function; if some test fails, there will be an error message. ''' assert string_to_number('') == (1,1) assert type(string_to_number('')) == tuple assert string_to_number('L') == (1,2) assert type(string_to_number('R')) == tuple assert string_to_number('LR') == (2,3) assert type(string_to_number('RL')) == tuple assert string_to_number('RL'*5) == (144,89) assert type(string_to_number('LR'*10)) == tuple assert string_to_number('LLLLLLLLLLL') == (1,12) assert string_to_number('RRRRRRRRRR') == (11,1) print("all tests passed")

The algorithm to compute the path to a particular pair of integers (m,n) is rather simple: 1. Begin with a pair of integers (m,n) and let S= ' be the empty string 2. If mn, set m to be mn and add R on to the end of S(SSR) 4. If m=n, the process stops and the path S is found 5. Until this happens, repeat step 2 or 3 depending on the condition It can be proved (it's easy, but we skip it as well) that this repetition will stop after a finite number of step. Your first task in this homework, is to write a function which will compute the path towards the number on the binary tree for a rational number given by the pair of (m,n); this function is to be called number_to_string (m,n). Your second task, is to reverse the problem, and compute the pair of positive mutually prime integers (m,n) which is represented on the binary tree by the string-path s, consisting of symbols L and R only. The code you start with: \#\# You should implement two functions number_to_string (m,n) and \#\# string_to_number(s). The 'pass'statements are only a placeholder \#\# which you should replace with your implementation. The first function, \#\# number_to_string (m,n) must return a string representing the rational \#\# number m; the second function, string_to_number(s), must return a p \#\# of mutally prime positive integers m and n in a form of two-tuple (m,n) def number_to_string (m,n) : pass def string_to_number(s): pass<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 9 For Linux UNIX And Windows Advanced Database Administration Certification Certification Study Guide

Authors: Roger E. Sanders, Dwaine R Snow

1st Edition

1583470808, 978-1583470800

More Books

Students also viewed these Databases questions

Question

4. Choose appropriate and powerful language

Answered: 1 week ago

Question

2. Employees and managers participate in development of the system.

Answered: 1 week ago