Today, we will do a live version of a contest problem as our in-class quiz! You have 50 minutes to complete the challenge (and we have an extra credit problem for those who have more time).
We will use the same mechanism as with the contest problems that comprised an out-of-class programming assignment.
SCORING: Contest problems are typically scored in "all or nothing" fashion in that your program must produce precisely the correct output on all of the judge's hidden tests for you to get credit for solving the problem.
As a quiz question, you should submit your code whether you solved the problem or not, as we will give partial credit for the attempt. But for full credit on the quiz you will need to have correctly solved the problem in accordance with the contest rules.
SOURCE CODE: The source code for the required problem must be named digits.py (and for the extra credit problem, copier.py).
INPUT: Because the automated scoring is looking at your output, it is important that you not display any prompts to the user when seeking input. You should just assume that the user will type input that adheres to the specifications given in a problem. Also, you do not need to error-check any of the input. You should assume it is legitimate.
For flexibility, we will allow your script to read input in one of two ways:
You may read it using the standard input() function, but again you must not provide any prompt when using this function. In this case, to test your program you will need to type the input on the keyboard or you could copy/paste from another source into the window where input was expected while the program is running.
One disadvantage is that it requires a lot of typing. Also, it becomes a bit more difficult to differentiate your generated output when it might be intermingled with the input.
As an alternative approach, we will allow you to pre-type your input into a saved file, and then use that saved file as the input to your program. This has an advantage in that you can test and retest without having to retype (or copy) the input, and it will make the results cleaner in that only your output will be displayed (not the contents of the file). But to use this approach, we need to quickly teach you a bit about working with files. Also, for our automated testing to work, the name of that file must be fixed, so we will use the convention that it should be a .txt file with the same prefix as the source code (thus input in digits.txt for the problem solved by digits.py).
To get input from a file, you will need to first create a file object in Python using the following syntax:
manager = open('digits.txt')
You can subsequently use that object to get lines of
input, but rather than the standard input()
function you should make a call to
line = manager.readline() # returns the string of characters on the line, including the final newlineOnce you have that line of input as a string, you can do whatever you want with it (just as you can do with the result of the input() function). And you can make an additional call to manager.readline() each time you want an additional line of input.
TESTING: If on our department's system, you may pre-test your program against the judge's data by typing the following command at a console terminal from within the same folder in which your source code exists:
/public/goldwasser/1300/contest/judge digits.py
If you wish to otherwise test on your own system, we'll disclose that the judge's set of tests is digits.txt and the expected results can be found here.
SUBMISSION: One member of the pair must submit your program electronically, placing it in the quiz12 folder of their git repository.
Digits Solitaire (source code: digits.py)
Hints: Don't forget that if you have a numeric string s, you can compute its numeric value as int(s) and if you have an integer value k you can compute its string representation as str(k).
Copier Reduction (source code: copier.py)
Since this is extra credit, we'll use more strict contest rules whereby you will only get credit if you correctly solve the problem.