ITECH1400: Fundamentals of Programming - Computer Science Assignment
- Subject Code :
ITECH1400
- Country :
Australia
Task -1 Building Thue-Morse Sequence
In this task you are required to write a Python function named thue_morse(n), that takes a positive integer parameter, n, and returns the string tn (defined above). In your program you
may define other (auxiliary) functions with arbitrary names, however, the solution function of this task should be named thue_morse(n).
n this task we defined python function called thue_morse(n) and then we initialized two string values ‘0’ and ‘1’ to X and Y.
As the next step we created a for loop start from 0 and it will
iterate until n (whatever number we called in function). Inside the for loop, we have a function X and Y and inverse of X and Y as Y and X. Finally, it will return the value of X
Ta
sk
–
2 Building a square-free word in the alphabet of three symbols
2.1. Construction of the Square-Free Word
2.2. The Programming Tasks
a)
You are required to write a Python function named square_free(n), that takes a positive
integer parameter n and returns the string an (defined above).Again, as in Task 1, you may define other (auxiliary) functions with arbitrary names,however, the solution function of this task should be named square_free(n)
b)
Write a Python function named print3Blocks(s) that takes a string, s, as a parameter and
prints it in blocks of 3 symbols separated by white spaces.
Task 3. Counting the number of squares in a string.In this task you are required to write a Python function named
count_squares(s)
that takes a string,
s
, as a parameter and returns the number of “squares” in
s
, i.e., the number of
occurrences of two consecutive identical sub-words in
s
.