Coding Bee #1

This coding bee consists of of three problems, all chosen from level 1 and 2 of the CCC Junior competition.  You have 90 minutes to complete the three problems.

Challenge #1: Speed Fines are Not Fine! (CCC/2012/J1)

Original problem description on CEMC website.

Many communities now have “radar” signs that tell drivers what their speed is, in the hope that they will slow down.  In an imaginary town, the fines for speeding are as follows:

  • 1 to 20 km/h over speed limit:                 $100
  • 21 to 30 km/h over speed limit:              $270
  • 31 or above km/h over speed limit:      $500

Input Specification: Prompt the user to enter two integers: first, the speed limit; second, the speed they are driving.

Output Specification: Print one of the following messages to the console:

  • “Thank you for obeying the speed limit.”
  • “You are driving X km/h over the speed limit and your fines is F.”  (Replace X and F with values calculated by your program).

Sample Input/Output:


Please enter the speed limit in km/h.
65
Please enter your speed in km/h.
78
You are driving 13 km/h over the speed limit and your fine is $100.

Challenge #2: Next in Line (CCC/2013/J1)

Original problem description on CEMC website

You know a family with three children. Their ages form an arithmetic sequence: the difference in ages between the middle child and youngest child is the same as the difference in ages between the oldest child and the middle child. For example, their ages could be 5, 10 and 15, since both adjacent pairs have a difference of 5 years.

Given the ages of the youngest and middle children, what is the age of the oldest child?

Input Specification: Prompt the user to enter two integers.  The first integer is age of the youngest child.  The second integer is the age of the middle child.

Output Specification: Print to the console, “The oldest child is X years old.”

Sample Input/Output:


Please enter the age of the youngest child.
4
Please enter the age of the middle child.
12
The oldest child is 20 years old.

Challenge #3: Sounds Fishy! (CCC/2012/J2)

Original problem description on CEMC website

A fish-finder is a device used by anglers to find fish in a lake. If the fish-finder finds a fish, it will sound an alarm. It uses depth readings to determine whether to sound an alarm. For our purposes, the fish-finder will decide that a fish is swimming past if:

• there are four consecutive depth readings which form a strictly increasing sequence (such as 3 4 7 9) (which we will call “Fish Diving”) (When the fish goes up, the depth readings go down because the fish is closer to the boat).

• there are four consecutive depth readings which form a strictly decreasing sequence (such as 9 6 5 2) (which we will call “Fish Rising”)

• there are four consecutive depth readings which are identical (which we will call “Constant Depth”).

  • All other readings will be considered random noise or debris, which we will call “No Fish.”

Your task is to write a function that reads a sequence of depth readings and determine if the alarm will sound.

Input Specification: Your function should take 4 inputs, which are all integers.  These are the first, second, third, and fourth depth readings.  Therefore, the first line of your function should be:


def FishFinder(a,b,c,d)

Output Specification: Your function should return one of the following strings:

  • “Fish Rising”
  • “Fish Diving”
  • “Constant Depth”
  • “No Fish”

Sample Input/Output:


>>> FishFinder(3, 5, 18, 29)
"Fish Diving"