Problem Set 1
Problem Set 1
Problem Set #1
This Problem Set is due at 11:59 pm Pacific time on 2024-09-19, and will be submitted on Canvas.
This Problem Set is worth 6% of the final course grade. There are five problems.
Problems #1 and #2 and #3 are to be completed individually, while Problems #4 and #5 are to
be completed in your assigned small groups. For the two group problems, you are strongly encouraged,
though not required, to have a different lead author for each of parts (a), (b), and (c).
Please type (or neatly handwrite) your solutions on standard 8.5 × 11 (or A4) paper, with your name(s)
at the top of each solution. Ensure that you submit five separate PDF files on Canvas, one for each
problem. Make sure you label your Problem Set #1 submissions appropriately - e.g. timothy-1-1.pdf,
timothy-1-2.pdf, timothy-1-3.pdf, timothy-1-4.pdf, timothy-1-5.pdf.
Given that the last two problems are done in a group, your final two PDF files will be identical to
some of your classmates. (For example, timothy-4.pdf might be identical to yvonne1-4.pdf and bethany1-
4.pdf). This is completely fine, and enables you to have a record of all of your submitted work in this
course.
While a solution must be absolutely perfect to receive full marks, I will be generous in awarding partial
marks for incomplete solutions that demonstrate progress.
So that there is no ambiguity, there are two non-negotiable rules. A violation of either rule constitutes
plagiarism and will result in you receiving an F for this course.
(a) If you meet with a classmate to discuss one of the Problems, the articulation of your thought process
(i.e., what you submit to me), must be an individual activity, done in your own words, away from
others. Please remember that the solution-writing process is where so much of your learning will
occur in this course - even more than the time you spend on solving the problems. Do not be
surprised if it takes you 3 to 5 times as long to write up a solution as it takes you to actually solve
the problem.
(b) This Problem Set has been designed to be challenging, because struggling through problems is how
we learn best. When stuck on a problem, it can be helpful to get a small hint that will allow you to
make some progress without robbing you of the opportunity to solve the problem. Online searches,
and even well-intentioned classmates, may be unable to provide you with just a small insight. If
you need support/a small hint, the best plan is to post your query on the Canvas discussion forum.
I will be readily available during office hours, or by appointment.
CS 5002, Fall 2024 Semester, Timothy Edmunds – Problem Set #1 2
Problem #1 – INDIVIDUAL
Humans are usually most comfortable working in base 10 (decimal). However, computers work in base 2
(binary).
As an example, your computer has an Internet Protocol (IP) address. An IP is like your home mailing
address, uniquely identifying where a computer is in a network of computers. IP addresses are 32-bit
binary numbers, commonly expressed in the dotted-decimal format in which the 32 bits are grouped into
four bytes (each byte has 8 bits).
(a) Convert 10100101 from binary to decimal, and convert 10100101 from binary to hex. Show your
steps.
(b) Suppose Tim’s IP address is 67.89.0A.BC in hex. Determine Tim’s IP address, both in binary and
also in dotted-decimal format. Show your steps.
(c) Currently there are an estimated 4.5 billion Internet users, each having at least one device that re-
quires a unique IP address. Calculate the number of possible IP addresses, and use your calculation
to explain why there are not enough (32-bit) IP addresses for everyone.
CS 5002, Fall 2024 Semester, Timothy Edmunds – Problem Set #1 3
Problem #2 – INDIVIDUAL
The Two’s complement representation allows us to represent negative numbers without using a negation
symbol.
For the purposes of this problem, we will assume all calculations are done with 8 bits. For example,
the 8-bit Two’s complement representation of +29 is 00011101, and the representation of -10 is 11110110.
(a) Determine the 8-bit Two’s complement representations of the (decimal) numbers 40, -40, 100, and
-100. Clearly show your steps.
(b) Compute the sums 100+40 and -100-40 just as a computer would, using the 8-bit Two’s complement
representations you found in part (a). Explain why both calculations result in an incorrect answer.
(c) Suppose x is a decimal number whose Two’s complement representation begins with 0, and suppose
y is a decimal number whose Two’s complement representation begins with 1. Can the sum x + y
ever result in an incorrect answer? If so, explain how. If not, explain why not.
CS 5002, Fall 2024 Semester, Timothy Edmunds – Problem Set #1 4
Problem #3 – INDIVIDUAL
You have a double pan balance scale on which you can place weighted objects on both sides.
For example, if you have two objects, one with weight 5 and one with weight 7, you can measure items
of weight 5, 7, or 12.
You can also measure items of weight 2, by placing 7 on one side and 5 on the side which contains
the object to be weighed. If the scale balances, you know that the item has weight 2 since 5+2=7.
Your goal is to measure items of weight N , where N is any whole number between 1 and 40.
(a) Suppose you have six objects, with weights 1, 2, 4, 8, 16, 32. Clearly explain how you can use the
balance scale to measure an item of weight N , where N is any whole number between 1 and 40.
(b) Suppose you have four objects, with weights 1, 3, 9, 27. Clearly explain how you can use the balance
scale to measure an item of weight N , where N is any whole number between 1 and 40.
(c) Suppose you have three objects, with weights A, B, C. Determine whether there exists a set of
three weights A, B, C for which you can use the balance scale to measure an item of weight N ,
where N is any whole number between 1 and 40.
If these three weights exist, determine the values of A, B, C. If these three weights do not ex-
ist, clearly explain why this problem is impossible to solve.
CS 5002, Fall 2024 Semester, Timothy Edmunds – Problem Set #1 5
Problem #4 – GROUP
In this problem, you will determine the day of the week on which you were born!
You will need to answer this question for each person in your group. If you are uncomfortable shar-
ing your birthday with us, please replace it with the birthday of anyone in your life (e.g. parent, child,
sibling, partner, best friend, etc.) The choice is yours.
(a) January 1, 2024 was a Monday. Using this information, determine the day of the week that your
birthday will (or did) fall on in the year 2024. Clearly show the steps in your calculations.
(b) Now determine the day of the week on which you were born. Once again, clearly show the steps in
your calculations.
I strongly encourage you to use your result from part (a) which should make your calculation
easier. For example, if you know the answer for December 25, 2024, you can use this information
to determine the day of week for December 25, 1998. (How?)
(c) Alex was born on the 15th day of month M, in the year 1978. Alex was born on a Thursday.
Determine Alex’s birthday. Clearly justify your answer.
(d) (OPTIONAL BONUS). See if you can create a Python program to solve the Calendar Problem!
Your program will input three variables (Year, Month, Day) and will output the correct day of the
week corresponding to that Year, Month, and Day.
CalendarCalculation(\YearVar, 9, 27)
will return Friday. You can submit either a Python notebook (.ipynb) or Python script (.py); for
either, include thorough documentation.
(There is some required domain knowledge that you will need to incorporate into your solution to this
problem: the number of days in a week, the number of days in each month of the year, the number of
days in a year. Also, note that you will need to account for leap years. Every year that is evenly divisible
by 4 is a leap year. Except that years that are evenly divisible by 100 are not leap years. Except that
years that are evenly divisible by 1000 are leap years.)
CS 5002, Fall 2024 Semester, Timothy Edmunds – Problem Set #1 6
Problem #5 – GROUP
In the game of Nim, Florence and Roy take turns removing stones from distinct piles. Florence moves first.
On each turn, a player must remove at least one stone, and may remove any number of stones pro-
vided they all come from the same pile. The player who removes the last stone wins the game.
In class, we analyzed the game where the starting configuration was (1, 2, 3, 4, 5). In other words, there
are five distinct piles, with the number of stones being 1, 2, 3, 4, and 5, respectively.
We then calculated the “Nim Sum” (also known as the binary digital sum) of this starting configu-
ration, where we converted each number to binary, and then added the bits of the five binary numbers
using the Exclusive Or (XOR) operation, where 1+1 = 0.
Before starting the questions below, I encourage you to confirm your understanding of this concept
by verifying the following: 3 ⊕ 5 = 6, 3 ⊕ 6 = 5, 3 ⊕ 5 ⊕ 6 = 0, 2 ⊕ 5 ⊕ 7 = 0, 1 ⊕ 2 ⊕ 4 = 7.
(a) Suppose the starting configuration has a Nim Sum of 0. (An example of such a configuration is
(2, 5, 7).) Clearly explain why any move Florence makes changes the Nim Sum to a number bigger
than 0.
(b) Suppose the starting configuration has a Nim Sum bigger than 0. (An example of such a configu-
ration is (1, 2, 4).) Clearly explain why there exists at least one move that Florence can make that
turns the Nim Sum to 0.
(c) Suppose the starting configuration is (1, 2, 3, 5, 6). Clearly explain why Florence can always win
this game, no matter how perfectly Roy plays. Finally, find all three possible opening moves for
Florence, and explain why Florence must make one of these three moves to ensure victory.