Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

CPSC 121 Winter 2, 2020

HW 4
Due: 19:00, Thursday April 13, 2021
Instructions:
1. Do not change the problem statements we are giving you. Simply add your
solutions by editing this latex document. To make it easier for the TAs to find
your solutions, please use the soln environment we provided as follows:

\begin{soln}
My solution is here.
\end{soln}

Your solution will then appear in blue, and be easier to differentiate from the
questions.
2. If you need more space, add a page between the existing pages using the
\newpage command.
3. Export the completed assignment as a PDF file for upload to gradescope.
4. On Gradescope, upload only one copy per partnership. You must identify
you group via Gradescope, not doing so may result in loosing some marks
5. You must also tell us, via Gradescope, where each of the problem parts
appears on your submission. You MUST align the regions for every problem,
even if your assignment solution isn’t complete. We will not be able to mark
any problem we can’t find. After uploading the .pdf you will a screen, where
you can click each question on the left, and click the corresponding page(s) for
which the question appears in. Because of this matching process, please allocate
at least 5 minutes prior to the deadline for submission. You must match your
answers with each question, not doing so may result in loosing some marks.
Academic Conduct: I certify that my assignment follows the academic
conduct rules for of CPSC 121 as outlined on the course website. As part of
those rules, when collaborating with anyone outside my group, (1) I and my
collaborators took no record but names away, and (2) after a suitable break,
my group created the assignment I am submitting without help from anyone
other than the course staff.

1
CPSC 121 Winter 2, 2020

1. [8 marks] Prove that for every three non-zero integers a, b and c, at least one of the
three products ab, ac, bc is positive. Hint: use a proof by contradiction.

2
CPSC 121 Winter 2, 2020

2. [6 marks] Design a sequential circuit that takes in a sequence x1 , x2 , . . . xn of unsigned


8 bit integers as inputs (one input each clock cycle), and outputs True if the values follow
the Fibonacci sequence, where the first and second values are both 1. Your circuit should
include a reset input which, if set to True, clears the state of your circuit and allows you
to begin entering a new sequence after setting reset back to False.
Assume that your circuit outputs True immediately after resetting. Our solution uses
four sequential devices in total, in addition to other combinational devices.

3
CPSC 121 Winter 2, 2020

3. [8 marks] The Fibonacci numbers are defined as follows: F0 = F1 = 1 and for every
i ≥ 2, Fi = Fi−1 + Fi−2 . We thus get the sequence

1, 1, 2, 3, 5, 8, 13, 21, 34, 55, . . .

Prove by induction that


n
X
Fi = Fn+2 − 1
i=0

4
CPSC 121 Winter 2, 2020

4. [8 marks] Consider the tetrominoes in the following diagram:

From left to right, we will refer to these shapes as “O”, “L”, and “T” tetrominoes respec-
tively. Assume that each “square” of a tetromino occupies a single square unit area.
Prove, using strong induction, that any rectangular area with dimensions x × y, where
x and y are natural numbers each ≥ 2, and xy ≡ 0 mod 4 can be perfectly tiled using
only multiples of the three tetrominoes above. You are allowed to rotate the pieces, but
flipping (mirroring) is not necessary.

5
CPSC 121 Winter 2, 2020

5. [6 marks] Write a regular expression over the alphabet of {0..9, /} (i.e. numerals and
forward slash) that accepts strings representing positive rational numbers.

6
CPSC 121 Winter 2, 2020

6. [8 marks] Design a deterministic finite-state automaton (DFA) that accepts exactly


the strings over the alphabet {A, B, . . . , Z} that contain at least two R, at most one T, and
where every E comes after some S (there may be other letters in between). For instance,
your DFA should accept the strings:

• MYSTICWARRIORS
• MARSMATRIX
• SHOCKTROOPERS
• CONTRAHARDCORPS
• STRIDER

but not the strings

• CRAZYTAXI (it does not contain at least two Rs)


• LASTRESORT (it contains more than one T)
• AFTERBURNER (there are Es without a S somewhere before them)
• BATTLECIRCUIT (all of these at the same time)

Clearly indicate the meaning of each state. Hint: there are three separate conditions
accepted strings must meet; states will need to encode whether or not they are met. You
can label an edge with the word “else” to indicate it would contain every character that
does not appear on another edge leaving from the same state. For instance, if a state has
outgoing edges labeled “E”, “R”, “S”, “T” and “else”, then “else” stands for “A, B, C, D, F,
G, H, I, J, K, L, M, N, O, Q, U, V, W, X, Y, Z”. Our solution uses 15 states in total,
with 3 “garbage” states to prevent crossing lines.

You might also like