Adapting algorithms to diverse contexts

Assignment Help Programming Languages
Reference no: EM133137577

ITECH1400 Fundamentals of Programming - Federation University

ASSIGNMENT 1 - THUE-MORSE SEQUENCES

Overview
In this assignment you will have the opportunity to test your Python skills in generating and manipulating text. Throughout the assignment you are expected to apply the principles of problem solving that we have already discussed in this course.

Learning Outcome 1: Identify and use the correct syntax of a common programming language.
Learning Outcome 2: Recall and use typical programming constructs to design and implement simple software solutions.
Learning Outcome 3: Explain the importance of programming style concepts (documentation, mnemonic names, indentation).

Learning Outcome 4: Utilise pseudocode and/or algorithms as a major program design technique.
Learning Outcome 5: Write and implement a solution algorithm using basic programming constructs.
Learning Outcome 6: Describe program functionality based on analysis of given program code.

Learning Outcome 7: Develop self-reliance and judgement in adapting algorithms to diverse contexts.
Learning Outcome 8: Design and write program solutions to identified problems using accepted design constructs.

ASSESSMENT DETAILS

Introduction. The Thue-Morse sequence is an 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)¯ 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 ti+1 can be seen as an extension of ti.

This sequence of extensions can be performed infinitely many times, thus building 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). Thue-Morse sequence has multiple applications ranging from Chess to Group Theory and Differential Geometry.

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).

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

In this task you are required to write a function in Python that builds 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:

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, which are zero-based.

Below you can see the 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 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. For example, print3Blocks(a3) will print:

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'.

Attachment:- Fundamentals of Programming.rar

Reference no: EM133137577

Questions Cloud

Improved it for better result-relationship : Knowing what you know now, how would you have improved it for a better result, relationship, or both? How did it make you feel and what was your response?
Prepare the journal entries to account the sale : Prepare the journal entries to account the sale and leaseback transaction on both books of the sellerlessee and buyer-lessor
Issue for each hrm functions : Identify ONE (1) issue for each HRM functions and detailed analysis of the problems. Based on the chosen discussion, identify 1 problem for each. Total = 2 issu
Specializes in cutting certain types of meat : Tommy is a butcher at large grocery store. There are 12 people in the meat department and each one specializes in cutting certain types of meat. Tommy's job is
Adapting algorithms to diverse contexts : Explain the importance of programming style concepts (documentation, mnemonic names, indentation) and Describe program functionality based on analysis
Talking about diversity and start working toward equity : In the TedxPortland presentation, 'Let's Stop Talking About Diversity and Start Working Toward Equity, speaker Paloma Medina argues that our brains categorize E
Give the required journal entries for the two events : Kelly's Camera Shop had sales revenue of $160,000, Give the required journal entries for the two events in December
Main categories of citizenship behaviors : Research suggests two main categories of citizenship behaviors that differ according to who benefits from the activity
Calculate the npv of the cash flows : Calculate the NPV of the following cash flows using a 10% discount rate. Year 0= -400, Year 1= -90, Year 2= +100, Year 3= +400, Year 4= +500

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a program accept the institution name

Write a program - student names and you should also accept three (3) most favourable subjects for each student

  Construct and animate a solution to frogs and toads puzzle

COMP332 Programming Languages Assignment - Solving the Frogs and Toads problem in Scala, Macquarie University, Australia

  Create room and potentially booking classes

Show guest bookings then they are prompted to enter the guest ID - and then any bookings made by that guest are displayed including

  Program to accept inputs from user beginning temperature

Physicists tell us that lowest possible temperature is absolute zero. Absolute zero is -459.69 degrees Fahrenheit. Accept inputs from user: a beginning temperature, ending temperature, and increment value (all Fahrenheit).

  Write program which prompts for boiling point of substance

Write program which prompts user for observed boiling point of substance in Centigrade and identifies substance if observed boiling point is within 5% of the expected boiling point.

  Write html form that prompts user to enter value

Write an HTML form that prompts the user to enter a value. In PHP, write a script to determine whether the value contains an integer , a decimal-place number.

  Create a math program to practice math skills

Creating a Math Program to practice Math Skills. Ask the user what type of math problem they would like (addition, subtraction, multiplication, division, modulas).

  Two-dimensional array represent number of times bug reached

Two-dimensional array (N X M) must be utilized to represent number of times the bug reached each tile on floor. All cells of this array must be initialized to zero.

  Develop a calendar and scheduling system

Develop a calendar and scheduling system, This assignment will contain two (2) Parts: Written Paper and Visual Basic Prototype. The Visual Basic Prototype is not included in the total page count but is included in the evaluation of your assignment...

  Program to design a decision structure and a loop structure

A palindrome is a word or phrase that reads the same forwards and backwards, character for character, disregarding punctuation, case and spaces

  Write a program that calculates the average waiting time

Write a program that calculates the average waiting time for a given workload using SRTF nd, for the sake of comparison, both SJF (non-preemptive) and FCFS.

  Comparing running time of two algorithm

Which algorithm would you prefer on the basis of running time, suppose all other factors equal?

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