Canadian Computing Competition: 2010 Stage 1, Junior #1
Natalie is learning to count on her fingers. When her Daddy tells her a number (
), she asks "What is
, Daddy?", by which she means "How many fingers should I hold up on each hand so that the total is
?"
To make matters simple, her Daddy gives her the correct finger representation according to the following rules:
- the number may be represented on one or two hands;
- if the number is represented on two hands, the larger number is given first.
For example, if Natalie asks "What is , Daddy?", her Dad may reply:
is
.
is
and
.
is
and
.
Your job is to make sure that Natalie's Daddy gives the correct number of answers.
Input Specification
The input will be a single integer such that
.
Output Specification
The output is the number of ways of producing that number on two hands, subject to the rules outlined above.
Sample Input
4
Output for Sample Input
3
Comments
This task turned out to be way harder than I initially thought it would be.
I did this wrong and tried to figure out what was wrong when I input 11 than I saw that hint and got the maximum amount of points!
Can't you just use a 10 branch if statement for all the number of fingers.
This comment is hidden due to too much negative feedback. Show it anyway.
Would you show 5 on the right hand and then on the left? Does that count as 1 possibility?
Any duplicate cases would only be counted once.
how did I get stumped for 20 minutes on a 3 pointer
Can anyone check my solution? Is there any other (maybe mathematical) way to solve this?
If you're looking for more mathematical solution try thinking about the same problem but make the number of fingers also a parameter. Instead of it being 5 and make
.
Could not figure out what I was doing wrong then I remembered we have only 5 fingers.
Oh darn I thought I had 40.
wait hold on the example says 3, what does 3 mean
3 is the number of ways to show 4.
4 is 4 is one way.
4 is 3 and 1 is another.
4 is 2 and 2 is the last one, because saying 4 is 1 and 3 would be the same as saying 4 is 3 and 1. Same goes with 4 is 0 and 4.
EDIT:
Yes CarolChen that is helpful.
@ CarolChen that's a very helpful hint, thanks
That was a very helpful comment thanks!