CMU 15-112 Summer 2020: Fundamentals of Programming and Computer Science
Homework 2 (Due Wed 20-May, at 5pm)
- This assignment is SOLO. This means you may not look at other student's code or let other students look at your code for these problems. See the syllabus for details.
- To start:
- Create a folder named 'hw2'
- Download hw2.py and cs112_m20_day2_linter.py to that folder
- Edit hw2.py using VSCode
- When you are ready, submit hw2.py to Autolab. For this hw, you may submit up to 20 times (which is way more than you should require), but only your last submission counts.
- Do not use string indexing, lists, or recursion in this assignment.
- Do not hardcode the test cases in your solutions.
Important note about spiciness levels!
Note: this homework has 2 levels: Medium and Spicy.
35 points of hw1 come from collab1. 20 points of hw1 come from the CT and ROC practice.
This leaves 45 points to gain from either nthCircularPrime or play112. Choose the problem at the level that is most appropriate for you.
- CT & ROC Practice [20pts - Required]
Download day2-ct-rc-runner.py
Log in with the username and password you received from us.
For full credit, you must complete a CT problem in under 5 minutes and an ROC problem in under 5 minutes.
For every minute it takes you to complete the problem over 5 minutes you will lose 20% of the score for that problem.
Only your best score is counted.
You have unlimited attempts to complete each type of problem in the time limit.
Important: To receive any credit, you must quickly upload a picture of your scrap work and your submission confirmation to this form after getting a correct answer.
Your picture should show:- Your scrap work and answer
- Your Andrew ID
- The results table including the problem statement, correct answer, and your answer
- nthCircularPrime [45 pts - Medium]
A circular prime is an integer number with the property that any rotation of that number's digits is prime. In this case, rotation refers to cycling the digits of a number; for example, the rotations of 1234 are 1234, 2341, 3412, and 4123. You can read more about this on the Wikipedia page. Single-digit primes are all circular, of course. To find the nth circular prime, you'll need to write isPrime and three other functions:
- rotateNumber [10 pts]
This function takes a non-negative integer number, x, and rotates that number's digits by one place. This would turn the number 1234 to 4123. - isCircularPrime [25 pts]
This function takes a non-negative integer number, x, and determines whether that number is a circular prime. To do this, you'll need to check whether every rotation of the number is prime. - nthCircularPrime [10 pts]
This function takes a non-negative integer number n, and returns the nth circular prime.
- rotateNumber [10 pts]
- play112 (The 112 Game) [45 pts - Spicy]
See "The 112 Game" here (skip to Part B). Be sure to follow the spec exactly, so the autograder can properly grade your work! Also, note that the test function in that writeup uses Python 2, but the one in the hw2.py file we provided uses Python 3.