Re: The RUN CHASE: A Challenge for the Programmer in U...
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Mon, 05 Apr 2010 12:00:16 +0100
news.telesweet.net wrote:
On 4/5/2010 5:49 AM, Richard Heathfield wrote:CVS wrote:In a game of cricket,
1. Assume you can score exactly as you want on each ball.
2. Single/Double/Triple/Four/Six are the options available to you on
each ball.(no extras)
3. RISK is defined as the square of the score on each ball.
* * * *
Write a program that accepts:-
a. Target runs to score (N)
b. No. of balls to score it in (x)
and prints the runs to score on each ball.
Remember U have to ACHIEVE the target with MINIMUM RISK possible.
Hypothesis: for scoring N, the minimum risk is achieved when you hit N
singles.
To score N + 1, we can do one of these things:
* reduce N to N-5, then add a six. The effect on the risk is that R[N+1]
is (R[N] - 5) + 36 = R[N] + 31, which is greater than R[N];
* reduce N to N-3, then add a four. This gives a risk greater than R[N]
by 4*4-3 = 13;
* reduce N to N-2, then add a three. This gives a risk greater than R[N]
by 3*3-2 = 7;
* reduce N to N-1, then add a two. This gives a risk greater than R[N]
by 2*2-1 = 3;
* simply add a single. This increases the risk by 1, the minimum.
Now the base cases. To score 0, the least risky score is 0. To score 1,
the least risky score is a single. To score 2, the least risky score is
two singles. To score 3, the least risky score is three singles. To
score 4, the least risky score is four singles. To score 5, the least
risky score is five singles. And just to be sure, to score 6 the least
risky score is six singles.
Induction has shown us that singles are always the safest way. Since the
overriding requirement is minimum risk, x is irrelevant and can be ignored.
You have implicitly assumed that x >= N in this argument. If x < N then it is simply impossible to score N on x balls by only scoring singles.
If x < N, you haven't minimised the risk, which is a requirement - in fact, it's the only requirement, and it's spelled out in CAPITAL LETTERS, so it's obviously vital. Therefore, x must be >= N.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
"Usenet is a strange place" - dmr 29 July 1999
Sig line vacant - apply within
.
- Follow-Ups:
- Re: The RUN CHASE: A Challenge for the Programmer in U...
- From: news.telesweet.net
- Re: The RUN CHASE: A Challenge for the Programmer in U...
- References:
- The RUN CHASE: A Challenge for the Programmer in U...
- From: CVS
- Re: The RUN CHASE: A Challenge for the Programmer in U...
- From: Richard Heathfield
- Re: The RUN CHASE: A Challenge for the Programmer in U...
- From: news.telesweet.net
- The RUN CHASE: A Challenge for the Programmer in U...
- Prev by Date: Re: The RUN CHASE: A Challenge for the Programmer in U...
- Next by Date: Re: The RUN CHASE: A Challenge for the Programmer in U...
- Previous by thread: Re: The RUN CHASE: A Challenge for the Programmer in U...
- Next by thread: Re: The RUN CHASE: A Challenge for the Programmer in U...
- Index(es):
Relevant Pages
|