Practice Problems¶
The purpose of the practice problems is to allow you to test you understanding of the material we are covering in lecture. There are two types of practice problems:
- “be-a-computer” warm-up exercises. You should do these warm-up exercises by hand. We’ll provide code to allow you to check your answers.
- Programming Problems. We will be using a system named Kattis for these problem. Kattis is a website that allows students to submit solutions to programming problems, and have them evaluated automatically by running a series of test cases on the submitted solutions. You can find information about how to use Kattis here.
Be-a-computer exercises¶
Kattis problems¶
For all these problems, we provide a Python file that will handle the
input/output aspect of the problem, so you can focus on solving the
programming problem itself. You can get the files for these problems
by running git pull upstream master
(they will be inside a
kattis
directory).
In most of these files, there will be code comments instructing you to only modify a specific piece of the provided code. Make sure you read these code comments and that you do not modify any code you’re not supposed to modify
Note: some problems refer to files being
in a hw
directory; please disregard this and look in the kattis
directory instead.
Problems with a (*) are challenge problems.
- Programming Basics
- Outside range (file:
outsiderange.py
)- Divisible by (file:
divisibleby.py
)- Within range (file:
withinrange.py
)
- Lists and Loops
- Count negative (file:
countnegative.py
)- List negate (file:
negate.py
)- (*) A tricky problem (file:
tricky.py
)
- Dictionaries
- Babelfish (file:
babelfish.py
)- Odd man out (file:
oddmanout.py
)- (*) Secure doors (file:
securedoors.py
)
- Exam #1 Practice Problems Note: These problems are not representative of the problems you will encounter in the exam. They simply build the kind of skills that will be important to do well in the exam.
- Pet (file:
pet.py
)- Mixed Fractions (file:
mixedfractions.py
)- Ragged Right (file:
raggedright.py
)- Planting Trees (file:
plantingtrees.py
)- Engineering English (file:
engineeringenglish.py
)- Flow Layout (file:
flowlayout.py
)- Quick Brown Fox (file:
quickbrownfox.py
)- Train Passengers (file:
trainpassengers.py
)- Bounding Robots (file:
boundingrobots.py
)- Hitting the Targets (file:
hittingtargets.py
)- Bus Numbers (file:
busnumbers.py
)- (*) Secret Message (file:
secretmessage.py
)- (*) Semafori (file:
semafori.py
)- (*) Reverse Minesweeper (file:
minesweeper.py
)- (*) Verify This, Your Majesty (file:
queens.py
)- (*) A winning strategy? (file:
martingale.py
)
Recursion Practice Problems Note: Many of these problems could be solved with an iterative algorithm as well. We expect you to solve these problems recursively, but please note that Kattis cannot tell whether your solution to a problem is recursive or not, so getting an “Accepted” judgement does not necessarily mean that your solution is correct.
Note (2): Several of these problems are from a placement exam. Please ignore any warning about what happens “on the exam”. Those warnings refers to the placement exam, not to the CS 121 exam.
- Dijkstra’s Other Algorithm (file:
gcd.py
)- Don’t Be Such a Square (file:
square.py
)- Ninety-One (file:
ninetyone.py
)- I Hope You’re Not Aibohphobic.... (file:
palindrome.py
)- Line Them Up (file:
lineup.py
)
- Exam #2 Practice Problems Note: Unless otherwise noted, these problems are not representative of the problems you will encounter in the exam. They simply build the kind of skills that will be important to do well in the exam.
- Black Friday (file:
blackfriday.py
)- Ferry Loading 4 (file:
ferryloading4.py
)- Permutation Encryption (file:
permutationencryption.py
)- Torn to Pieces (file:
torn2pieces.py
) This question is challenging. We recommend writing two functions: one that computes a dictionary that maps a station to a list of the stations to which it is directly connected and another that looks for a path between two stations.- Shortest Manhattan Distance (file:
shortmanhattan.py
). This recursion problem is from a previous CS 121 exam.- It’s All About the Miles (file:
miles.py
). This recursion problem is also from a previous CS 121 exam.