# Using Kattis¶

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.

We will be posting a number of exercises on Kattis that you can solve at any time. You are not required to solve these exercises, and they will not be graded, but they will be good practice. Plus, Kattis provides us with a mechanism to look at your submissions so we can provide feedback if you’re having trouble solving a problem.

## Setup¶

Before you can submit code through Kattis, you need to complete the following steps:

1. Go to the Open Kattis registration page and create an account with your UChicago e-mail. If you do not use your UChicago e-mail, we will not be able to find your submissions on Kattis.
3. Go to the CMSC 12100 Autumn 2015 page on Kattis, and click on the link that says “I am a student taking this course and I want to register for it on Kattis.”
4. Go to your User Settings (click on the user icon on the top-right corner of the Kattis page, and then select “User Settings”) and change the following:
• By default, the information on what problems you have solved is shown to everyone in the class (you can see what this looks like by clicking on the Queue link on the top of the site). If you would prefer not to show this information, check the “Anonymous mode” option.
• Set your preferred time zone to “America/Chicago”
• Set your default language to “Python 3”.

Before you attempt any of the problems we give you, you should try to solve the Hello World problem. This problem has a very simple solution: you just need to write a Python program that prints out a “secret message”, which happens to be exactly this text:

Hello World!


The way you submit a problem is by clicking on the green icon that appear to the left of the problem name (when you hover over the icon, it should say “Submit”). This will take you to a page where you can either upload a file, or switch to an editor where you can write the code directly on your browser. Make sure that you select Python 3 as the language before you submit.

After you’ve submitted the code, Kattis will “judge” it, and will send you an e-mail notification with the result. If you solved the problem correctly, you will get an “Accepted” judgement.

You can also check the status of all your submissions by clicking on the user icon on the top-right corner of the Kattis page, and then clicking on your name. This will show a list of all your submissions. Take into account that this list does not update automatically; if a submission shows up as pending (either “Compiling” or “Running”), you need to reload the page to see its latest status.

You can also get more details on any submission by clicking on the 6-7 digit number on the left column (this is number is the submission identifier).

Next, try to make an incorrect submission. Submit a Python program that prints this:

Hello CS 121!


The submission should be judged as “Wrong Answer”.

## Solving the problems we give you¶

We will be providing you with some starter code for most of the problems we give you. This starter code will handle the input/output aspect of the problem, since we will not be covering input/output until later in the quarter. Make sure that you use this code; you can ignore the “Input” and “Output” sections found in the problems.

The problems include some sample data that you can use to test your solution. However, Kattis will run your solution with additional test cases, typically designed to check corner cases. For example, one of the first problems you will work on requires you to check whether a number $$x$$ is strictly outside a range $$(y\ldots z)$$. If you get that problem wrong, you may want to check whether your code is correctly handling the case where $$x$$ is equal to either $$y$$ or $$z$$.

If you get a “Wrong Answer”, make sure you look at the details of that submission (by going to the list of submissions and clicking on the submission identifier). This will show you how many of the instructors’ test cases you are passing.

Kattis may return judgements other than “Accepted” and “Wrong Answer”. You can see a list of all the possible Kattis judgements here: https://uchicago.kattis.com/documentation/judgements

## Testing your solution before submitting to Kattis¶

Before submitting a solution to Kattis, you may want to run your solution on your own machine to make sure there are no major issues with your code, such as syntax errors or small mistakes that will makes your code return a Wrong Answer even with the sample input.

Suppose we give you a file called problem.py as a starting point. Once you’ve modified that file with your solution, you can run it like this:

python problem.py


The program will appear to get stuck (like it had fallen into an infinite loop). This is normal: the program is actually waiting for input. Go to the problem statement on Kattis, and copy any of the sample inputs. For example, in the Divisible By problem, the first sample input is:

0 10 2 3


Copy that text, and paste it into the terminal (note: to paste in the terminal, you need to use Control-Shift-V; you can also just type the input directly). Press Enter, and then Control-D. This will make the problem run with the provided input, and it will print out an answer. If the answer matches the sample output provided in the Kattis problem statement, it means your solution works for that input. At this point, your solution is probably safe to submit to Kattis.

If, on the other hand, you get a Python syntax error or output that doesn’t match the expected output, you may want to debug your solution a bit more before you submit it on Kattis. Otherwise, you will have to debug it using the (sometimes limited) feedback that Kattis provides.