[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[QUIZ] Countdown (#7

James Gray

11/12/2004 2:19:00 PM

The three rules of Ruby Quiz:

1. Please do not post any solutions or spoiler discussion for this quiz until
48 hours have passed from the time on this message.

2. Support Ruby Quiz by submitting ideas as often as you can:

http://www.grayproductions.net/...

3. Enjoy!

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

by Brian Candler

One of the longest-running quiz shows on UK TV is called Countdown, and has
a "numbers round". There are some cards laid face down in front of the host
- the top row contains 'large' numbers (from the set 25, 50, 75, 100), and
the rest are 'small' (1 to 10). Six cards are picked and displayed: the
choice is made by one of the contestants, who typically will ask for one
large number and five small ones.

Next, a machine called "Cecil" picks a target number between 100 and 999 at
random. The contestants then have 30 seconds to find a way of combining the
source numbers using the normal arithmetic operators (+, -, *, /) to make
the target number, or to get as close as possible.

Each source card can be used no more than once. The same applies to any
intermediate results, although of course you don't have to explicitly show
the intermediate results.

Example: source 100 5 5 2 6 8, target 522

100 * 5 = 500
5 + 6 = 11
11 * 2 = 22
500 + 22 = 522

or more succinctly, (5*100)+((5+6)*2) = 522

Another solution is (100+6)*5-8 = 522

Normal arithmetic rules apply, and in particular you are not allowed to use
integer rounding. That is, 7 divided by 3 is 2 1/3, not 2.

The quiz is to write a program which will accept one target number and a
list of source numbers, and generate a solution which calculates the target
or a number as close to the target as possible.


27 Answers

Brian Schröder

11/12/2004 4:48:00 PM

0

> Next, a machine called "Cecil" picks a target number between 100 and 999 at
> random. The contestants then have 30 seconds to find a way of combining the
> source numbers using the normal arithmetic operators (+, -, *, /) to make
> the target number, or to get as close as possible.
>
> Each source card can be used no more than once.

I suspect that this means, each may (not be used or used exactly once)?

Regards,

Brian


James Gray

11/12/2004 5:55:00 PM

0

On Nov 12, 2004, at 10:47 AM, Brian Schröder wrote:

>> Next, a machine called "Cecil" picks a target number between 100 and
>> 999 at
>> random. The contestants then have 30 seconds to find a way of
>> combining the
>> source numbers using the normal arithmetic operators (+, -, *, /) to
>> make
>> the target number, or to get as close as possible.
>>
>> Each source card can be used no more than once.
>
> I suspect that this means, each may (not be used or used exactly once)?

That's how I read it.

James Edward Gray II




James Britt

11/12/2004 6:26:00 PM

0

James Edward Gray II wrote:

> On Nov 12, 2004, at 10:47 AM, Brian Schröder wrote:
>
>>> Next, a machine called "Cecil" picks a target number between 100 and
>>> 999 at
>>> random. The contestants then have 30 seconds to find a way of
>>> combining the
>>> source numbers using the normal arithmetic operators (+, -, *, /) to
>>> make
>>> the target number, or to get as close as possible.
>>>
>>> Each source card can be used no more than once.
>>
>>
>> I suspect that this means, each may (not be used or used exactly once)?
>
>
> That's how I read it.
>
> James Edward Gray II


So, if the target is 101, and among your numbers are 100 and 1, an
acceptable answer would be

100 + 1

True?


James

>
>



James Gray

11/12/2004 9:03:00 PM

0

On Nov 12, 2004, at 12:26 PM, James Britt wrote:

> So, if the target is 101, and among your numbers are 100 and 1, an
> acceptable answer would be
>
> 100 + 1
>
> True?

Absolutely.

James Edward Gray II



Hans Fugal

11/12/2004 11:32:00 PM

0

Ruby Quiz wrote:

> The quiz is to write a program which will accept one target number and a
> list of source numbers, and generate a solution which calculates the target
> or a number as close to the target as possible.

Is the input interactive, or whitespace-delimited, or what? YAML perhaps?

---
target: 522
sources: [100,5,5,2,6,8]
....

James Gray

11/12/2004 11:40:00 PM

0

On Nov 12, 2004, at 5:33 PM, Hans Fugal wrote:

> Ruby Quiz wrote:
>
>> The quiz is to write a program which will accept one target number
>> and a
>> list of source numbers, and generate a solution which calculates the
>> target
>> or a number as close to the target as possible.
>
> Is the input interactive, or whitespace-delimited, or what? YAML
> perhaps?

The quiz didn't specify an input format. Personally, I'm using
command-line arguments. That seems pretty easy to me, but use whatever
you like.

Just don't make it too hard on me come testing time, please. :)

James Edward Gray II



James Gray

11/13/2004 1:13:00 AM

0

On Nov 12, 2004, at 8:19 AM, Ruby Quiz wrote:

> Example: source 100 5 5 2 6 8, target 522
>
> 100 * 5 = 500
> 5 + 6 = 11
> 11 * 2 = 22
> 500 + 22 = 522
>
> or more succinctly, (5*100)+((5+6)*2) = 522
>
> Another solution is (100+6)*5-8 = 522

Anyone find a tricky example? I doubt my algorithm, but I can't find
the right test to topple it.

James Edward Gray II



daz

11/13/2004 6:19:00 AM

0


James Edward Gray II wrote:
>
> Anyone find a tricky example? I doubt my algorithm, but I can't find
> the right test to topple it.
>


Target: 926
-------------------------------
Selection: 75 2 8 5 10 10
-------------------------------

p (75 - 5 + 8) * (2 + 10) - 10 #-> 926

This is the only solution and is difficult to find.

-----

Real nastiness here:
http://www.crosswordtools.com/numbers-game/?n1=25&n2=6&n3=3&n4=3&n5=7&n6=50&...

( this, and others, described in http://www.crosswordtools.com/numbers-ga... )


daz



Brian Schröder

11/13/2004 10:25:00 AM

0

On Sat, 13 Nov 2004 15:23:24 +0900
"daz" <dooby@d10.karoo.co.uk> wrote:

>
> James Edward Gray II wrote:
> >
> > Anyone find a tricky example? I doubt my algorithm, but I can't find
> > the right test to topple it.
> >
>
>
> Target: 926
> -------------------------------
> Selection: 75 2 8 5 10 10
> -------------------------------
>
> p (75 - 5 + 8) * (2 + 10) - 10 #-> 926
>
> This is the only solution and is difficult to find.
>

My Program found

((((75.0 - (2.0 / 5.0)) + 8.0) + 10.0) * 10.0) = 926.0

is this not a solution?

Thanks,

Brian

--
Brian Schröder
http://www.brian-sch...



daz

11/13/2004 1:13:00 PM

0


Brian Schröder wrote:
> >
> > p (75 - 5 + 8) * (2 + 10) - 10 #-> 926
> >
> > This is the only solution and is difficult to find.
> >
>
> My Program found
>
> ((((75.0 - (2.0 / 5.0)) + 8.0) + 10.0) * 10.0) = 926.0
>
> is this not a solution?
>


It's not allowed in the television game:

"... all the steps to the solution must be whole numbers.
e.g. You cannot start by dividing 7 by 5 and then use
1.4 in subsequent steps."


Nevertheless, I look forward to seeing your program.
If you leave it to find "all" possible solutions,
this should be 1.0 of them.

(75.0 - 5.0 + 8.0) * (2.0 + 10.0) - 10.0 #-> 926.0

:-)


daz