Lab 1 (Year 2 Sem 2)

Lab 1 is the second lab in semester 2 of year 2, and the 15th lab in the total of year 2. It is a lab for "A&A", and is considered easy.

Description
No description was provided for this lab.

Unlocked after completion

 * Optional1 (Score at least 75% for Lab1 - A&A)

Question
Question 1: Collatz

Given the positive number n, output the number of steps need to reach 1

Implementation Sample 
 * Implement collatz(n), where n is a positive number
 * collatz(1) = 0
 * collatz(2) = 1

Solution
This is like Year 2 Sem 1 Lab 6.2 Question 1.

Question
Question 2: Trick

Story Line: refer to the notes

Implementation
 * Implement the function trick
 * The input is the string of 'A', 'B' or 'C'
 * The functions returns the answer required

Sample
 * trick('AB') returns 3
 * trick('ABAB') returns 2

Solution
Store the current position of the ball with a variable. For each letter in the function's input, modify the variable accordingly.

Question
Question 3: Test

There is a test going on. Every question is an MCQ with three options, A, B or C. Each question is 1 mark. Three students, X, Y and Z are taking the test but they do not study for the test, so they have to guess the answer to all the questions.

Student X will guess in the sequence of A, B, C, A, B, C, A, B, C, ...

Student Y thinks this sequence is better: B, A, B, C, B, A, B, C, B, A, B, C, ...

Student Z is using the sequence: C, C, A, A, B, B, C, C, A, A, B, B, ...

Given the correct the answers to the test, determine the highest score of them.

Implementation: Sample
 * Implement function test
 * The input is a string, representing the sequence of the correct answers.
 * This function returns the highest score of them.
 * test('BAACC') returns 3
 * test('AAAABBBB') returns 4

Solution
Make a function to get the current guess for each student

Then, iterate over the argument, adding 1 to the student's score where needed.

Question
Question 4: Calendar

Implementation Sample Remarks: you can not import any module or package.
 * Implement a function cal(day, month)
 * Day and month represent the date in the Year 2034, the input are guaranteed valid.
 * This function returns the day of week of that date.
 * cal(1,1) returns 'Sunday'. ie. 1st Jan 2034 is a Sunday. Some may find this information useful.
 * cal(27,7) returns 'Thursday'

Solution
Since cal(1,1) is Sunday, cal(2,1) should be Monday. cal(1,2) is 31 days since Jan 1, so it is Wednesday on that day.