Challenge 1 (Year 2 Sem 1)

Challenge 1 is the first challenge in semester 1 of year 2, and the first challenge in the total of year 2. It is a challenge for Python fundamentals and modules, and is considered to be easy.

Description
Questions in this training are meant to "test" your problem solving ability using concepts covered in unit 2 and 3. You should not need concepts beyond unit 2 and 3.

Prerequisites

 * Complete Lab 2: Python Fundamentals
 * Complete Lab 3: Modules
 * Complete Review 1: Introduction to Python
 * Complete Review 2: Python Fundamentals
 * Complete Review 3: Modules
 * Complete Practice 1 [Chapter 3]

Unlocked after completion

 * Intern of the Year (Score at least 60% for Challenge 1: Python Fundamentals & Modules)
 * Well Calculated (Score at least 60% for Challenge 1: Python Fundamentals & Modules)
 * Challenge 2: Selection (Score at least 100% for Challenge 1: Python Fundamentals & Modules)

Question
You will start in your hometown, Perth, drive across Australia to Sydney, and then back again to Perth. There are three routes between Perth and Sydney. In your market research, you have counted the number of customers living along each route. You wish to plan your trip to Sydney and back so that you visit the greatest number of customers possible. You must take a different route on the return journey, otherwise you would simply end up visiting the same satisfied customers twice.

Your task is to write a program which, given the number of customers along each of the three routes between Perth and Sydney, determines the greatest number of customers you can visit by travelling from Perth to Sydney and back.

Input: The input variables northern, central, southern is a single integer (whole number), representing the number of customers on the northern, central and southern routes respectively. Each route will contain between 0 and 1000000 customers, inclusive.

Output: Your function should return an integer which is the greatest number of customers you can visit by driving from Perth to Sydney and back again.

Solution
You can either use a lot of if-else statements, or sort the three numbers in a list and return the first (or last) two.

Question
Yarr! Welcome aboard the Black Pearl! I'm Captain Mia Swamp, and this is my First Matey, Growlybills. We've heard you're handy with these computing contraptions, so I'll make you a deal: help us out with a little problem, and we won't feed you to the sharks.

You're in? Thought so.

See that map yonder? That long, thin island there is the Isle of Obstaclewick. Boring place. All you need to know is that it's L nautical miles long from east to west, and so thin we all just say it has zero width.

Our ship, the Black Pearl, is sailing the north coast of the island, X nautical miles from the west point. See the other ship, the one sailing the south coast, Y nautical miles from the west point? That's the HMS Smallerout, our target. It may look like a wibbly-wobbly old thing, but it's carrying some of Britain's greatest treasures.

We can sail either way around the Isle of Obstaclewick, approaching the Smallerout from either side. What we want you to do is tell us which way is shorter. We don't want to overwork the... volunteers... in the galley. So that's your job, landlubber! Write us a program that calculates the shortest distance we have to sail to reach the Smallerout! Constraints

Note that:


 * 1 ≤ L ≤ 10,000, where L is the length of the Isle of Obstaclewick, given in nautical miles.
 * 0 ≤ X,Y ≤ L, where X and Y are the positions of the Black Pearl and the HMS Smallerout respectively, given in nautical miles from the west point of the Isle.

Input:

The input variables are L, X and Y.

Output:

Your function should return an integer which is the shortest distance the Black Pearl must travel to reach the HMS Smallerout, given in nautical miles.

Solution
Compare the two possible distances, and return the one which is smaller.

Question
In the latest trend of skin-tight jeans and slimline handbags, having a bulging wallet or purse is simply a fashion crime. You are faced with a dilemma: either you find yourself disowned by your fashion-conscious friends, or risk carrying too little money for your taxi ride home.

You wish to carry the exact amount of money for your taxi ride (in case you are mugged or otherwise lose it). However, you also wish to use as few notes as possible to avoid being ridiculed by your friends. The notes available to you come in denominations of $1, $5, $20 and $100 (you never carry coins, which are simply far too bulky).

For example, if your taxi fare costs $67, the smallest number of notes you can carry is six — this is achieved by carrying three $20 notes, one $5 note and two $1 notes (20+20+20+5+1+1 = 67).

Your task is to determine the smallest number of notes you need to carry in order to make up a given taxi fare.

Input:

The input variable t is the cost of your taxi ride home. It is guaranteed that 0 <= t <= 1,000,000.

Output:

Your function should return an integer which is the fewest number of notes required to make up your taxi fare.

Solution
For each possible denomination, add the quotient of the fare divided by it to the total count, then set the fare to be equal to the remainder.

Question
You used to like ninjas. That was before the shadowy shiro-obi ninja clan moved in next door. They're mostly decent neighbours - they keep to themselves and never throw loud parties - but every few nights they sneak into your house and raid the kitchen. With no one else to turn to, you decide to take matters into your own hands and catch them in the act.

There are N ninjas trying to get inside, one at a time. You wait and watch carefully, grabbing the first one who comes past. However, in the time it takes you to securely tie up this first ninja, K other ninjas manage to sneak past you. Nevertheless, you persevere, grabbing the next ninja. Again, while you tie them up, K more ninjas sneak past. This continues until all of the ninjas have tried to get in.

In the above example, K=2. That is, for each ninja you tie up, the following two ninjas will sneak past. You catch the first ninja who comes past, and then ninjas #2 and #3 sneak past you. You catch ninja #4, and then ninjas #5 and #6 sneak past you. This repeats until all N ninjas have either been caught or have snuck past you. Your task is to write a program that reads in the values of N and K, and calculates the number of ninjas who sneak past you.

Constraints

The value of N and K will adhere to the following bounds:
 * 0 ≤ N ≤ 10,000, where N is the number of ninjas trying to get inside.
 * 0 ≤ K ≤ 10,000, where K is the number of ninjas who sneak past you every time you catch one.

Input

The input are two integers N and K.

Output

The output should be a single integer: the number of ninjas who sneak past you.

Solution
Use a for loop to iterate over the ninjas (1 to N + 1), and if the remainder when the current number is divided by K + 1 is not 1, add one to the count.