Develop self-reliance and judgement in adapting algorithms

Assignment Help Programming Languages
Reference no: EM133509443

Fundamentals of Programming

ASSIGNMENT 1 - THUE-MORSE SEQUENCES

Overview
In this assignment you will have the opportunity to test your Python skills in generating and manipulating text.

Knowledge:
K1. Identify and use the correct syntax of a common programming language.
K2. Recall and use typical programming constructs to design and implement simple software solutions.
K4. Explain the importance of programming style concepts (documentation, mnemonic names, indentation).

Skills:
S1. Utilise pseudocode and/or algorithms as a major program design technique.
S2. Write and implement a solution algorithm using basic programming constructs.
S4. Describe program functionality based on analysis of given program code.

Application of knowledge and skills:
A1. Develop self-reliance and judgement in adapting algorithms to diverse contexts.
A2. Design and write program solutions to identified problems using accepted design constructs.

ASSESSMENT DETAILS

Task 1. Constructing a Cube-Free Word in the Alphabet of Two Symbols.
In this task you are required to develop a Python program that constructs an arbitrarily long (potentially infinite) cube-free word in the alphabet of two symbols, ‘0', ‘1'. I.e., a word that does not contain "cubes" - three consecutive identical sub- words.
Such words (sequences) are called Thue-Morse sequences and have multiple applications ranging from Chess to Group Theory and Differential Geometry.

Construction of the Cube-Free Word: The Thue-Morse sequence is a (potentially) infinite word in the alphabet of two symbols, ‘0' and ‘1', which can be constructed in the following way:
(0) t0 = ‘0'
(1) t1 = ‘0' + ‘1' = ‘01'
(2) t2 = ‘01' + ‘10' = ‘0110'
(3) t3 = ‘0110' + ‘1001' = ‘01101001'
...

(n) tn = tn-1 + tn-1‾, where tn-1‾ denotes the ‘inverse' of tn-1,

i.e., all ‘0's in tn-1 are replaced by ‘1's and vice versa.

...
It is easy to see that each ti is the first half of ti+1, and therefore ti+1 can be seen as an extension of ti.

This sequence of extensions can be continued indefinitely, thus constructing an infinite word, T, which contains all tis as its prefixes (beginnings):

T = ‘0110100110010110100101100110100110010110011010010...'

T has an important property: it does not contain "cubes", i.e., three consecutive identical blocks (sub-words).

Programming Task. 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 in the previous section).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).

In your report, you are required to submit a brief explanation of your program in plain English. It will be useful in confirming ownership of your work.

Task 2. Constructing a square-free word in the alphabet of three symbols.

In this task you are required to write a function in Python that constructs an arbitrarily long (potentially infinite) square- free word in the alphabet of three symbols, ‘1', ‘2', ‘3'. I.e., a word that does not contain "squares" - two consecutive identical sub-words.

Although, this can be done by using the Thue-Morse sequence, in this task we will use another construction, suggested by S. Arshon.

Construction of the Square-Free Word: Again, as in Task 1, we will build a sequence of finite words, ai, that can be extended to an infinite word.

We start with a0 = ‘1'.

Each next word, ak+1, is constructed by replacing each occurrence of the symbols ‘1', ‘2', ‘3' in the previous word, ak, with 3- letter words according to the following rules:

(1) if symbol ‘1' is in an odd position in ak, then it is replaced with the word ‘123', if ‘1' is in even position, it is replaced with ‘321'.

(2) if symbol ‘2' is in an odd position in ak, then it is replaced with the word ‘231', if ‘2' is in even position, it is replaced with ‘132'.

(3) if symbol ‘3' is in an odd position in ak, then it is replaced with the word ‘312', if ‘3' is in even position, it is replaced with ‘213'.

Here's the table repeating the replacement rules in a tabular format:

Symbols in odd positions

Replacement string for odd positions

Symbols in even positions

Replacement string for even positions

1

123

1

321

2

231

2

132

3

312

3

213

Please note, that in this description the first symbol is considered to be in position 1. Therefore, you will need to make the necessary adjustments when using Python strings since they are zero-based.

Below, you can see first few steps of the construction process:

a0 = ‘1'
a1 = ‘123'
a2 = ‘123132312'
a3 = ‘123132312321312132312321231'
...
A = ‘1231323123213121323123212312132313213123212313213121323...'

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 in the previous section).
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).

In your report, you are required to submit a brief explanation of your program in plain English. It will be useful in confirming ownership of your work.

(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. For example, print3Blocks(a3) will print:

123 132 312 321 312 132 312 321 231

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.

For example, count_squares (‘1231233') should return 2 as there are two "squares" in its argument: ‘1231233' and ‘1231233'.

In your report, you are required to submit a brief explanation of your program in plain English. It will be useful in confirming ownership of your work.

Reference no: EM133509443

Questions Cloud

How your personal philosophy aligns with philosophers belief : The philosopher's contributions to the education system of the United States. How your personal philosophy aligns with the philosopher's beliefs.
Which instances do you believe the inclusion of product : which instances do you believe the inclusion of product placements in the films shaped their scripts and production practices, either for better or worse?
What will you take away from reading hannahs gifts : What will you take away from reading Hannah's Gifts - that will be useful to you professionally, as a CLS and a grief supporter?
Determine fundamental approaches to scientific research : Determine fundamental approaches to scientific research in addressing questions related to the natural world Develop questions about fundamental aspects
Develop self-reliance and judgement in adapting algorithms : ITECH1400 Fundamentals of Programming, Federation University - write a Python function named count_squares(s) that takes a string, s, as a parameter and returns
Discusses something written by jones : The book used is by Smith, but Smith discusses something written by Jones, so who do I cite, Smith or Jones? You will need to cite the "primary source".
What potential solutions have you discovered : What potential solutions have you discovered? What are areas that the authors of research studies have suggested for future investigations?
What additional cultural facts would you have had to know : consider one cross-cultural encounter that you found especially awkward or difficult, for example, in your own neighborhood, at work, or while traveling.
What is the main problem that the supervisor is trying : What is the main problem that the supervisor is trying to solve? What is the purpose of the message: to inform, persuade, regulate or collaborate?

Reviews

Write a Review

Programming Languages Questions & Answers

  Design an appropriate set of classes to solve the problem

The purpose of this project is for you to demonstrate your understanding of object oriented software development in practice.

  Write a recursive method writeblock

Write a recursive method writeBlock (char, int, int) that uses the recursive method writeLine (char, int) to write m lines of n characters each. For example, writeBlock (‘ *' , 5, 6) produces the following output:

  Write the definitions for the classes described

Write the definitions for the classes described above and a program to test your classes. Create a typescript output (using the command script).

  Create application to use scrollable control track

Create the Application which permits you to enter amount of a purchase and then display the amount of sales tax on the purchase. Use a scrollable control such as a track bar to adjust the tax rate.

  Create program in pseudocode to compute amount of money

Create the program in pseudocode which computes the amount of money a person would earn over period of time if their salary is one penny first day.

  Write an F function which takes an integer x

CS:3820 Programming Language Concepts Assignment - Write an F# function isIn: int-> ilist -> bool which takes an integer x and an ilist l

  Pseudocode to create thread-safe countdownevent by locks

Write pseudocode to implement a thread-safe CountdownEvent using locks and condition variables by implementing the following methods (lists 4 methods) and then "implement a Barrier using a CountdownEvent.

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Write program to prints formatted table of windchill values

Write a program which prints nicely formatted table of windchill values. Rows must represent wind speed for 0 to 50 in 5 mph increments.

  Write program to compute volume flow rate

Write program to compute volume flow rate in cubic feet per second of water flowing through a pipe of diameter d in inches and a velocity of v feet per second.

  Different class maintain programming programs are organized

It allows different classes to maintain programming so that programs are kept more organized. Object orientation also allows a programmer to use the same objects in different programs. Response?

  Write a program to compute the sum of two matrices

EEL 2161 Electrical Engineering Computer Methods Assignment. Write a program to compute the sum of two matrices and then print it. Firstly user will be asked to enter the order of matrix (number of rows and columns) and then two matrices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd