## CCC '13 J1 - Next in line

View as PDF

Points: 3
Time limit: 3.0s
Memory limit: 256M

Problem type
##### Canadian Computing Competition: 2013 Stage 1, Junior #1

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

The input consists of two integers, each on a separate line. The first line is the age of the youngest child . The second line is the age of the middle child .

#### Output Specification

The output will be the age of the oldest child.

#### Sample Input 1

12
15

#### Output for Sample Input 1

18

#### Sample Input 2

10
10

#### Output for Sample Input 2

10

• commented on Sept. 14, 2022, 5:45 p.m.

dam I am getting the output but still says I'm wrong :((((

• commented on Sept. 14, 2022, 6:10 p.m. edit 2

Are you really getting the correct output? What about for sample input 2?

Hint: You're outputting 2m-12 but you should be outputting 2m-y. If you want it to work for all test cases, because it never said y=12 for all cases.

• commented on July 28, 2022, 9:42 a.m.

It's like taking two (M)iddle children and substracting the (Y)oungling.

• commented on June 14, 2022, 6:38 p.m.

Nice one! Glad I had my notebook next to me, and a pencil. Then the old school "remove all the unnecessary text so the formula can start to show up.

• commented on May 3, 2022, 1:19 a.m.

input: 12 - 15 - output: 18

input: 5 - 10 - output: 15

• commented on April 8, 2022, 8:20 a.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on April 8, 2022, 1:45 p.m.

Why would it? Failure to read instructions put onto the output specification will result in WA. It clearly said to just output the age of the oldest child, nothing else.

• commented on March 31, 2022, 10:17 p.m.

i dont know what this question wants...

• commented on April 1, 2022, 12:46 a.m. edited

input: 12 - 15 - output: 18

input: 5 - 10 - output: 15

is there a pattern?

• commented on April 8, 2022, 1:50 p.m.

You could say there is a pattern, I would suggest rereading the problem carefully to understand what the question wants, rather than just looking at input and outputs to find a pattern.

• commented on Jan. 10, 2022, 11:14 a.m.

I don’t understand why people state “math puzzles” shouldn’t exist in problem solving challenges.

You are instructing your computer to solve a task for you. It does not matter if its a math problem or a physics question. Programming it relevant to any subject.

Basic Algebra can go the long way:

Formulae: (M “Enter operand” Y)”operand” M = Old_B

Figure it how to convert that into code.

• commented on July 4, 2022, 4:45 p.m.

Computer science is related to math in many ways

• commented on June 8, 2020, 12:46 a.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Jan. 3, 2022, 10:32 p.m. edited

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on June 8, 2020, 7:21 p.m.

It's not really a coding problem, Henry. I would say its a math puzzle and coding it should be done last. First try to see what the problem is saying, and see how those test cases relate to the problem. For example, how are 12 and 15 related and why does the test case give you an answer of 18? Think about how the answer is formed.