A document from MCS 260 Fall 2021, instructor Emily Dumas.
You can also get the notebook file.

- Course instructor: Emily Dumas

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.

- Documents and videos posted to the course web page
- Any of the optional textbooks listed on the course web page

**Ask** if you are unsure whether a resource falls under one of these categories.

Contact the instructor or your TA by email, in office hours, or on discord.

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.

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.

The last version you submit before the project deadline is the one that will determine your score.

This section will explain a mathematical process that is used in the program you'll write.

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

- The largest digit of
`100`

is`1`

- The largest digit of
`5284`

is`8`

- The largest digit of
`620`

is`6`

- The largest digit of
`1200000000`

is`2`

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:

- The length of
`100`

is`3`

- The length of
`8`

is`1`

- The length of
`5284`

is`4`

- The length of
`1200000000`

is`10`

*Now, the essential definition:*

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`

.

Here is an example:

- Start with
`n = 5284`

- The largest digit is
`d=8`

- The length of
`n`

is`k=4`

`d**k = 8**4 = 4096`

- The sum of
`5284`

and`4096`

is`9380`

- Integer dividing
`9380`

by`2`

gives`m=4690`

So if we start with the integer `5284`

, then its mean with digit power is `4690`

.

The MWDP starts with one integer and gives you another one. You can repeat this process again to get another integer, and so on.

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)

For example, if $n_0$ is `5284`

, then the first few terms of this sequence are:
$$ 5284, 4690, 5625, 3460, 2378, 3237, 2819, ... $$
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.

`mwdps.py`

¶Write a program called `mwdps.py`

that asks the user for a positive integer `n`

using the prompt `Starting value:`

.

The program should then print the terms of the mean with digit power sequence starting with `n`

, one per line.

**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.**

Otherwise, if 100 terms of the sequence have been printed and all of them are distinct, then the program should print "maxiter" and exit.

Note that this means the last line of the program's output will always be either

`maxiter`

or

`looped`

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.

- Test case where the user enters
`5`

:

Remark: In this case the sequence is just`Starting value: 5 5 5 looped`

`5,5,5,5,5,...`

- Test case where the user enters
`321`

:`Starting value: 321 321 174 258 385 448 480 496 612 414 239 484 498 613 414 looped`

- Test case where the user enters
`213687239`

:`Starting value: 213687239 213687239 300553864 217385796 302403142 151332643 80705169 61875945 52461333 27070474 16417637 11091219 27068970 35057845 25917530 34482125 25629670 34338195 38692458 40869589 41958155 42502438 29639827 36343274 21054037 13409419 28228070 22502643 12091129 27568925 35307823 26042519 34544620 18112118 17444667 11604734 8684767 5390959 5086964 4934966 4858967 4820968 4801968 4792468 4787718 3442435 1760280 1928716 3355842 2726497 3754733 2289138 3536053 1907994 3345481 2721316 1772429 3277699 4030334 2023359 3403164 1841550 1969351 3376160 2099851 3441410 1728897 3255933 4019451 4401210 2208797 3495883 4139426 4461197 4622083 3359617 4071293 4427131 2625337 1724440 1273991 3028480 2562816 2329984 3556476 2190009 3486489 4134729 4458849 4620909 4701939 4742454 2782998 3782983 4282976 4532972 4657970 4720469 4751719 4767344 2795443 maxiter`

The first three lines of your Python program must be comments in the following format:

```
# MCS 260 Fall 2021 Project 1
# Full Name
# Individual work declaration
```

In the second line, replace `Full Name`

with your full name.

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.

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`

.

You are encouraged, but not required, to include comments that contain explanatory text.

Do not use comments to disable code that you don't want to run. Instead, remove such code before submitting.

The autograder tests your program and grades it based on its **behavior**. The following tests will be run:

- Was a file called
`mwdps.py`

submitted? (**5 points**) - Does the Python interpreter accept the contents of
`mwdps.py`

as valid Python code? (**5 points**) - When
`mwdps.py`

is run, does it start successfully and wait for user input? (**5 points**) - When the program is given an integer as input, does it produce the expected output? (5 tests x 5 points per test =
**25 points**).- The five test integers used here will be different from the ones shown above.
- Partial credit will be given on test cases using the following rubric.
- 5 points is given if the output exactly matches the expected output.
- 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
- 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
- 1 point is given if the line immediately following the input prompt consists of the starting number, and nothing else

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).

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.

For example, it might make sense to try writing code that can do the following things:

- Compute the length of an integer
- Compute the largest digit of an integer
- Compute the MWDP of an integer
- Compute the first 10 terms of the MWDP sequence starting from a given integer (or first 100 terms)
- Compute terms of the MWDP sequence while also storing the ones computed so far in a list
- Stop computing terms of the MWDP sequence if a term is found that was previously seen

`len`

¶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:

In [78]:

```
len(51)
```

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.

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.

- 2021-09-11 Edit description of the manual review process to say that I might change autograder scores in cases of intentional wrongdoing
- 2021-09-08 Fixed the
`213687239`

test case - 2021-09-07 Initial publication