Question: ANSWER THE FOLLOWING QUESTION IN PYTHON PLEASE: #!/usr/bin/python3 import unittest # ------------------------------------------------------------------- # This question is based on Emil Post's Tag System (1943). # -------------------------------------------------------------------
ANSWER THE FOLLOWING QUESTION IN PYTHON PLEASE:
#!/usr/bin/python3
import unittest
# -------------------------------------------------------------------
# This question is based on Emil Post's Tag System (1943).
# -------------------------------------------------------------------
def tag3(start) :
'''Assume that start is a bit string, such as '100100'.
Generate a series of words where the first word is start, and each
new word is constructed from the previous word by the following rules:
1. if a word begins with 0,
then append 0101 and then delete the first three digits
2. if it begins with 1, then append 10, and delete the first three digits.
3. if a word is the empty string, then do not change it
For example, if start is '1111', then the series of words begins
as follows:
1111 starting word
110 append 10 => 111110 and delete first three digits => 110
10 appending 10 and deleting first three digits
0 appending 10 and deleting first three digits
01 appending 0101 and deleting first three digits
101 appending 10 and deleting first three digits
10 appending 10 and deleting first three digits
but we saw this word 10 before,
so just 6 words before a repeat
Return the number of words in the series before the next word
is already in the series, or 50, whichever is smaller.
For example,
tag3('1111') returns 6, since the 6th word is the same as an
earlier word (see example above).
'''
### YOUR CODE GOES HERE
pass
### YOUR CODE GOES ABOVE THIS LINE
# --------------------------------------------------------------
# The Testing
# --------------------------------------------------------------
class myTests(unittest.TestCase):
def test1(self):
self.assertEqual(tag3('100100'), 12)
def test2(self):
self.assertEqual(tag3('111000'), 14)
def test3(self):
self.assertEqual(tag3('1111'), 6)
def test4(self):
self.assertEqual(tag3('11110000'), 24)
def test5(self):
self.assertEqual(tag3('00000000000000000001010101'), 50)
if __name__ == '__main__':
unittest.main(exit=True)
# -------------------------------------------------------------------
# The End
# -------------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
