Metadata
Title
2X: Extra Practice
Category
general
UUID
3bf773ded81f459a884aaa0afc2f47f1
Source URL
https://cscircles.cemc.uwaterloo.ca/2x-extra-practice/
Parent URL
https://cscircles.cemc.uwaterloo.ca/
Crawl Time
2026-03-18T05:13:17+00:00
Rendered Raw Markdown
# 2X: Extra Practice

**Source**: https://cscircles.cemc.uwaterloo.ca/2x-extra-practice/
**Parent**: https://cscircles.cemc.uwaterloo.ca/

This lesson contains extra practice exercises, some of which are challenging. If you get stuck, feel free to skip to the next problem or lesson and come back later. You can always use the [My Progress](http://cscircles.cemc.uwaterloo.ca/user-page/) page to review all past exercises.

The first exercise is about debugging. It tries to use a formula that is not quite correct to compute population growth.

Coding Exercise: Growth Debugging

Fix the logic error in this program: it should calculate the population of your country for the next 3 years, assuming it starts with 1000 people in 2012, and the number of people increases by 10% each year. You can change at most three characters. \
 If you get stuck, click here for a hint.

You need to create an account and log in to ask a question.

populationIn2012 = 1000
populationIn2013 = populationIn2012 \* 0.1
populationIn2014 = populationIn2013 \* 0.1
populationIn2015 = populationIn2014 \* 0.1

|  |  |  |  |
| --- | --- | --- | --- |
|  |  |  |  |

The rest of the exercises in this lesson are about the `min` and `max` functions.

## Simplifying a complex expression

Multiple Choice Exercise: Simplification

What is a simplification of the following expression?

```
max(x - 3, min(x + 10, x + 5))
```

Your choice: Select onex + 10x + 5x - 3

Correct! Since `x + 5` is always smaller than `x + 10`, we can simplify `min(x + 10, x + 5)` to just `x + 5`. Then working our way outwards, the entire expression is `max(x - 3, x + 5)`. Since `x + 5` is always the maximum of these two numbers, that is the result.

## Complicating a simple expression

Coding Exercise: Complication

Assume that the grader defines two variables `A` and `B` for you. Write a program which prints out the value

```
min(A, B)
```

However, there is a catch: your program is not allowed to use the `min` function. Instead, use `max` in a clever way to simulate `min`. Hint, Method 1Hint, Method 2

You need to create an account and log in to ask a question.

|  |  |  |
| --- | --- | --- |
|  |  |  |

## Payment Calculator

Coding Exercise: Payment Calculator

A credit card company computes a customer's "minimum payment" according to the following rule. The minimum payment is equal to either $10 or 2.1% of the customer's balance, whichever is greater; but if this exceeds the balance, then the minimum payment is the balance. Write a program to print out the minimum payment using `min` and `max`. Assume that the variable `balance` contains the customer's balance. Your program does not need to print the dollar sign.\
 *Example 1*: if your `balance` is `1000`, then your program should print `21`. \
 *Example 2*: if your `balance` is `600`, then your program should print `12.6`. \
 *Example 3*: if your `balance` is `25`, then your program should print `10`. \
 *Example 4*: if your `balance` is `8`, then your program should print `8`. \
 Hint

You need to create an account and log in to ask a question.

|  |  |  |
| --- | --- | --- |
|  |  |  |

## Sorting Scramble

The final problem is a challenging problem, about sorting numbers in a weird way. There are better, simpler, and faster [sorting methods](http://en.wikipedia.org/wiki/Sorting_algorithm) that you can learn about after completing our introductory lessons.

If you get stuck, feel free to skip the problem. You can always come back to it later. Additionally, you can keep track of what you have or have not finished by visiting the [My Progress](https://cscircles.cemc.uwaterloo.ca/user-page) page.

Scramble Exercise: Sorting Scramble

**Code scramble**: make the program **sort** the three numbers `x`, `y` and `z` into increasing order, so that `x` has the smallest value, `y` has the next smallest value, and `z` has the largest value. \
*Drag and drop with your mouse to rearrange the lines.*Click for a hint.

- y = tmp
- tmp = max(x, y)
- z = tmp
- y = tmp
- x = min(x, y)
- x = min(x, y)
- tmp = max(y, z)
- tmp = max(x, y)
- y = min(y, z)

|  |
| --- |
|  |

Continue on to lesson 3!