CS133V - Programming Paradigms - Lab Sheet 1
Use python for each of these tasks. The tasks should be done in a single Jupyter notebook - use markdown
to show the section numbers as well as the question numbers.
Section I
1. Assume that a list of numbers is given to you. Using iteration, obtain the maximum value of the
numbers in the list.
2. Assume that a sorted list of numbers is given to you. Find out the index of a given number using
binary search method.
3. Assume that two matrices are given. Represent each of them as a list of lists. Using iteration, obtain
the product of these two matrices. Make sure to include code to check whether the two matrices can
be multiplied together.
4. Suppose you are given a file containing text in English. Write a Python script to find out the top five
frequently occuring words in the file. Think about what can be done if the number of words in the file
is large!
Section II
1. (From Project Euler) The following iterative sequence is defined for the set of positive integers:
n → n/2 (n is even)
n → 3n + 1 (n is odd)
Using the rule above and starting with 13, we generate the following sequence:
13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
It can be seen that this sequence (starting at 13 and finishing at 1) contains 10 terms. Although it
has not been proved yet (Collatz Problem), it is thought that all starting numbers finish at 1.
Which starting number, under one million, produces the longest chain?
NOTE: Once the chain starts the terms are allowed to go above one million.
2. (From Project Euler) Each new term in the Fibonacci sequence is generated by adding the previous
two terms. By starting with 1 and 2, the first 10 terms will be:
1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
By considering the terms in the Fibonacci sequence whose values do not exceed four million, find
the sum of the even-valued terms.
Section III (https://eecs390.github.io/lab/lab01/)
Problem 1 (Conway’s game of life) from this page. You can use the starter code provided on this webpage.