CMU 15-112 Spring 2017: Fundamentals of Programming and Computer Science
Lab 2 (Due Thursday 26-Jan, at 10pm)
This lab has 2 required forms -- one to make groups and one to peer-review each others' groupwork (in terms of being great groupmates, not in terms of getting right answers).
- Group Formation Form: Due Tuesday 11:59pm [2.5 pts]
Fill out one of the following forms: Your group will be confirmed via email before Wednesday at 8am. At that point your group is final unless your group members are unresponsive, in which case you should email Eddie (edryer). - Group Peer-Review Form: Due Thursday 11:59pm [2.5 pts]
Fill out this peer review form once for each member of your group.
- This lab is Collaborative. No solo work allowed!. Work in groups of 2-3 (and the same group the whole time). See the syllabus for more details. Be sure to list your collaboration partners (name and andrew id) in a comment on the first line of this file!
- Even though this is collaborative, you may not directly copy any code from anyone, and you may not electronically share your code with anyone.
- Be a good lab partner! Help everyone in your lab group, and accept their help if you need it. Don't be in a hurry to finish the problems. Instead, take your time and be sure that everyone in the lab group is following and understanding. The goal is to learn, not just to finish.
- To start:
- Create a folder named 'week2'
- Download both lab2.py and cs112_s17_linter.py to that folder
- Edit lab2.py using pyzo
- When you are ready, submit lab2.py to autolab. For this lab, you may submit up to 10 times, but only your last submission counts.
- Do not use strings, lists, or recursion this week.
- Do not hardcode the test cases in your solutions.
Reminder: do not work on these problems alone -- only work on them together with your lab partners!
- isRotation(x, y)
Write the function isRotation(x, y) that takes two non-negative integers x and y, both guaranteed to not contain any 0's, and returns True if x is a rotation of the digits of y and False otherwise. For example, 3412 is a rotation of 1234. Any number is a rotation of itself. - nthEmirpsPrime(n)
Write the function nthEmirpsPrime(n) that takes a non-negative int n and returns the nth "Emirp prime", where an Emirp prime is a prime number which becomes a different prime number when its decimal digits are reversed. For example, 13 is an Emirp prime because when we reverse the digits we get 31, which is also prime. 2, 3, 5, 7, and 11 are all examples of primes that are not Emirp primes because they are the same prime when the digits are reversed. Here are the first several Emirp primes: 13, 17, 31, 37, 71, 73, 79, 97, 107, 113, 149, 157, 167, 179, 199,... So nthEmirpsPrime(0) returns 13. Aside: in case you missed it, emirp is prime spelled backwards. Also, we didn't make this up (check out "emirp" on Wikipedia)! - carrylessAdd(x, y)
First, read the first page (page 44) from here about Carryless Arithmetic. Fun! Then, write the function carrylessAdd(x, y) that takes two non-negative integers x and y and returns their carryless sum. As the paper demonstrates, carrylessAdd(785, 376) returns 51. - nthWithProperty309(n)
We will say that a number n has "Property309" if its 5th power contains every digit (from 0 to 9) at least once. 309 is the smallest number with this property. Write the function nthWithProperty309 that takes a non-negative int n and returns the nth number with Property309.