{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# MCS 260 Fall 2021 Project 1\n",
"\n",
"* Course instructor: Emily Dumas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Instructions\n",
"\n",
"### Deadline is 6pm CDT on Friday September 17, 2021\n",
"\n",
"### Collaboration policy and academic honesty\n",
"\n",
"This project must be completed **individually**. Seeking or giving aid on this assignment is prohibited; doing so constitutes academic misconduct which can have serious consequences. The only resources you are allowed to consult are the ones listed below. If you are unsure about whether something is allowed, ask. The course syllabus contains more information about the course and university policies regarding academic honesty.\n",
"\n",
"### Resources you are allowed to consult\n",
"\n",
"* Documents and videos posted to the course web page\n",
"* Any of the optional textbooks listed on the course web page\n",
"\n",
"**Ask** if you are unsure whether a resource falls under one of these categories.\n",
"\n",
"### What to do if you are stuck\n",
"\n",
"Contact the instructor or your TA by email, in office hours, or on discord.\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## What to submit\n",
"\n",
"The rest of this document describes a program `mwdps.py` you need to write and submit to Gradescope. That is the only file you need to submit for this project."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## When to submit\n",
"\n",
"The autograder will open on Monday, September 13. At that time it will be possible to submit your project. It's a good idea to submit a working but incomplete program as early as possible so you can see what the autograder report looks like.\n",
"\n",
"The last version you submit before the project deadline is the one that will determine your score."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Defining the *Mean With Digit Power* (MWDP)\n",
"\n",
"This section will explain a mathematical process that is used in the program you'll write.\n",
"\n",
"Suppose `n` is a positive integer. For the purposes of this project, we use the term **largest digit** of `n` to refer the decimal digit appearing in `n` that has the largest value. For example\n",
"* The largest digit of `100` is `1`\n",
"* The largest digit of `5284` is `8`\n",
"* The largest digit of `620` is `6`\n",
"* The largest digit of `1200000000` is `2`\n",
"\n",
"Also, we'll call the number of digits in a number `n` its **length** (again, for this project; this isn't standard terminology). For example:\n",
"* The length of `100` is `3`\n",
"* The length of `8` is `1`\n",
"* The length of `5284` is `4`\n",
"* The length of `1200000000` is `10`\n",
"\n",
"*Now, the essential definition:*\n",
"\n",
"Starting from a given integer `n` we define a new integer `m` as follows: Take the largest digit of `n` and call it `d`. Then, take the length of `n` and call it `k`. Then `m` is defined to be the result of adding `n` and `d**k` and then integer-dividing by 2. We call `m` the **mean with digit power** (MWDP) of `n`.\n",
"\n",
"Here is an example:\n",
"* Start with `n = 5284`\n",
"* The largest digit is `d=8`\n",
"* The length of `n` is `k=4`\n",
"* `d**k = 8**4 = 4096`\n",
"* The sum of `5284` and `4096` is `9380`\n",
"* Integer dividing `9380` by `2` gives `m=4690`\n",
"\n",
"So if we start with the integer `5284`, then its mean with digit power is `4690`."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Defining the *Mean With Digit Power Sequence*\n",
"\n",
"The MWDP starts with one integer and gives you another one. You can repeat this process again to get another integer, and so on.\n",
"\n",
"That is, if we are given a starting integer $n_0$, we can define an infinite sequence of integers $n_i$ by the rule that $n_{i+1}$ is the mean with digit power of $n_{i}$. We call this the **mean with digit power sequence** (or MWDPS)\n",
"\n",
"For example, if $n_0$ is `5284`, then the first few terms of this sequence are:\n",
"$$ 5284, 4690, 5625, 3460, 2378, 3237, 2819, ... $$\n",
"This means that the mean with digit power of `5284` is `4690`, and the mean with digit power of `4690` is `5625`, and so on."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## The program you need to write: `mwdps.py`\n",
"\n",
"Write a program called `mwdps.py` that asks the user for a positive integer `n` using the prompt `Starting value: `.\n",
"\n",
"The program should then print the terms of the mean with digit power sequence starting with `n`, one per line.\n",
"\n",
"**If the program ever prints a term that already appeared earlier in the sequence, the program should detect that, print \"looped\" on the next line, and exit immediately.**\n",
"\n",
"Otherwise, if 100 terms of the sequence have been printed and all of them are distinct, then the program should print \"maxiter\" and exit.\n",
"\n",
"Note that this means the last line of the program's output will always be either\n",
"```\n",
"maxiter\n",
"```\n",
"or\n",
"```\n",
"looped\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Examples of expected output from the program\n",
"\n",
"The test cases below show what output the program should produce when certain numbers are entered. Keep in mind that your program needs to work with any nonnegative integer, not just the ones shown here."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Test case where the user enters `5`:\n",
"```\n",
"Starting value: 5\n",
"5\n",
"5\n",
"looped\n",
"```\n",
"Remark: In this case the sequence is just `5,5,5,5,5,...`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Test case where the user enters `321`:\n",
"```\n",
"Starting value: 321\n",
"321\n",
"174\n",
"258\n",
"385\n",
"448\n",
"480\n",
"496\n",
"612\n",
"414\n",
"239\n",
"484\n",
"498\n",
"613\n",
"414\n",
"looped\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"* Test case where the user enters `213687239`:\n",
"```\n",
"Starting value: 213687239\n",
"213687239\n",
"300553864\n",
"217385796\n",
"302403142\n",
"151332643\n",
"80705169\n",
"61875945\n",
"52461333\n",
"27070474\n",
"16417637\n",
"11091219\n",
"27068970\n",
"35057845\n",
"25917530\n",
"34482125\n",
"25629670\n",
"34338195\n",
"38692458\n",
"40869589\n",
"41958155\n",
"42502438\n",
"29639827\n",
"36343274\n",
"21054037\n",
"13409419\n",
"28228070\n",
"22502643\n",
"12091129\n",
"27568925\n",
"35307823\n",
"26042519\n",
"34544620\n",
"18112118\n",
"17444667\n",
"11604734\n",
"8684767\n",
"5390959\n",
"5086964\n",
"4934966\n",
"4858967\n",
"4820968\n",
"4801968\n",
"4792468\n",
"4787718\n",
"3442435\n",
"1760280\n",
"1928716\n",
"3355842\n",
"2726497\n",
"3754733\n",
"2289138\n",
"3536053\n",
"1907994\n",
"3345481\n",
"2721316\n",
"1772429\n",
"3277699\n",
"4030334\n",
"2023359\n",
"3403164\n",
"1841550\n",
"1969351\n",
"3376160\n",
"2099851\n",
"3441410\n",
"1728897\n",
"3255933\n",
"4019451\n",
"4401210\n",
"2208797\n",
"3495883\n",
"4139426\n",
"4461197\n",
"4622083\n",
"3359617\n",
"4071293\n",
"4427131\n",
"2625337\n",
"1724440\n",
"1273991\n",
"3028480\n",
"2562816\n",
"2329984\n",
"3556476\n",
"2190009\n",
"3486489\n",
"4134729\n",
"4458849\n",
"4620909\n",
"4701939\n",
"4742454\n",
"2782998\n",
"3782983\n",
"4282976\n",
"4532972\n",
"4657970\n",
"4720469\n",
"4751719\n",
"4767344\n",
"2795443\n",
"maxiter\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Code style rules - IMPORTANT\n",
"\n",
"\n",
"### Required header\n",
"The first three lines of your Python program must be comments in the following format:\n",
"\n",
"```\n",
"# MCS 260 Fall 2021 Project 1\n",
"# Full Name\n",
"# Individual work declaration\n",
"```\n",
"\n",
"In the second line, replace `Full Name` with your full name.\n",
"\n",
"In the third line, replace `Individual work declaration` with a single full sentence, written in your own words, explaining that you completed the project individually and followed the rules in the syllabus and project description.\n",
"\n",
"### Use good variable names\n",
"\n",
"You are expected to choose variable names that communicate a variable's purpose in a concise way, but without being too terse. Uninformative low-effort names like `intvar` or `mystring` are not acceptable. Single-letter variable names can be used, but sparingly, and should usually be avoided for lists or other complex data structures. Most of the time, a good variable name will be a single word, like `total` or `sequence` or `step`.\n",
"\n",
"### Use comments to explain, not to disable code\n",
"\n",
"You are encouraged, but not required, to include comments that contain explanatory text.\n",
"\n",
"Do not use comments to disable code that you don't want to run. Instead, remove such code before submitting."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## How your project will be graded\n",
"\n",
"### Autograder: 40 points\n",
"\n",
"The autograder tests your program and grades it based on its **behavior**. The following tests will be run:\n",
"\n",
"1. Was a file called `mwdps.py` submitted? (**5 points**)\n",
"2. Does the Python interpreter accept the contents of `mwdps.py` as valid Python code? (**5 points**)\n",
"3. When `mwdps.py` is run, does it start successfully and wait for user input? (**5 points**)\n",
"4. When the program is given an integer as input, does it produce the expected output? (5 tests x 5 points per test = **25 points**).\n",
" - The five test integers used here will be different from the ones shown above.\n",
" - Partial credit will be given on test cases using the following rubric.\n",
" - 5 points is given if the output exactly matches the expected output.\n",
" - 4 points is given if the first three lines of output after the input prompt match the first three numbers of the MWDPS for the requested number\n",
" - 3 points is given if the first two lines of output after the input prompt match the first two numbers of the MWDPS for the requested number\n",
" - 1 point is given if the line immediately following the input prompt consists of the starting number, and nothing else\n",
"\n",
"### Manual review: 5 points\n",
"\n",
"I will review your code and look for adherence to the style guidelines given above, and examine your method of solving the problem. If I see that your program does not do what was requested in this document, but the error was not detected in the automated testing, a deduction may be given at this point. The scores assigned by the autograder will not be changed during manual review unless I discover some kind of intentional wrongdoing (such as an attempt to circumvent or reverse-engineer the autograder's operation)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Hints, tips, and warnings"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Break the task into small parts\n",
"\n",
"Try to find simpler programs that do something related to the project that you can write first. Get those working, and build up gradually to the full program described above.\n",
"\n",
"For example, it might make sense to try writing code that can do the following things:\n",
"* Compute the length of an integer\n",
"* Compute the largest digit of an integer\n",
"* Compute the MWDP of an integer\n",
"* Compute the first 10 terms of the MWDP sequence starting from a given integer (or first 100 terms)\n",
"* Compute terms of the MWDP sequence while also storing the ones computed so far in a list\n",
"* Stop computing terms of the MWDP sequence if a term is found that was previously seen\n",
"\n",
"### Length and `len`\n",
"\n",
"You can compute the length of a string or list in Python using `len()`. However, this function does not apply to integers, and in particular it will not let you compute the thing we've called the \"length of an integer\" above. If you call `len()` on an integer, you will get an error:"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "object of type 'int' has no len()",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m51\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m: object of type 'int' has no len()"
]
}
],
"source": [
"len(51)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"It *is* possible to compute the length (i.e. number of digits) of an integer using Python, but you'll need to do something slightly different."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Test locally\n",
"\n",
"As you write your project, test it locally on your own computer or the lab computer you use for your work. That is, run it in powershell or Terminal and make sure it works. It is *much* harder to debug a broken program based solely on reports you get from the autograder compared to working with your local Python interpreter."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Revision history\n",
"\n",
"* 2021-09-11 Edit description of the manual review process to say that I might change autograder scores in cases of intentional wrongdoing\n",
"* 2021-09-08 Fixed the `213687239` test case\n",
"* 2021-09-07 Initial publication"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 4
}