Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Geek Culture / Countdown Number Round Challenge

Author
Message
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Mar 2008 19:12 Edited at: 28th Mar 2008 19:13
In the UK, we have a quiz program called Countdown. One of the rounds involves solves a number problem, and I wondered how you could go about creating a program that can find the solution. I have found other on the net, but it would still be interesting to come up with a coding algorithm that does it.

Here is how the challenge works.

You choose 6 random numbers, ranging between 1 and 100.
Another random number between 1 and 999 is generated. You must create a sum from the 6 numbers where the answer equals the generated answer. You can add, subtract, divide and multiply. Integer numbers only all the way.

For example:6 numbers: 3,3,4,8,10,50
Generated answer: 919

Solution

8 x 10 = 80
80 x 4 = 320
320 + 3 = 323
323 x 3 = 969
969 - 50 = 919

So, how do you create a program that can check all combinations and find a solution? You don't have to use all the numbers.
Aertic
17
Years of Service
User Offline
Joined: 2nd Jul 2007
Location: United Kingdom
Posted: 28th Mar 2008 19:14
Sounds uhmmm, odd?
I'll chack through that again, also Ive watched countdown before, its good.

Just tell me if its over sized, its my first attempt at a sig.

[URL]www.Redarrow.forums1.net[/URL]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Mar 2008 19:17
My first thought on creating a solution is this:

1. Work out all the different ways of arranging 6 individual numbers. e.g:

n1 + n2 + n3 + n4 + n5 + n6
n1 - n2 -n3...
n1 + n2 - n3 + n4...
n1 x n2 x n3...

This obviously needs optimising, it's just a rough outline.

2. repeat for 5 numbers. Before you can do this, you need to establish all the combinations of 5 numbers. This would be any 5 from the 6. But it would also be:

(n1 + n2) + the other 4
(n1 + n3) + the other 4
(n1 x n2) + the other 4
and so on...

3. Repeat for 4 numbers, 3 numbers, 2 numbers.

That would cover all options, but there is obviously a lot of padding to put into those statements.
Agent Dink
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location:
Posted: 28th Mar 2008 19:38
Sounds like something I don't want to deal with

Aertic
17
Years of Service
User Offline
Joined: 2nd Jul 2007
Location: United Kingdom
Posted: 28th Mar 2008 20:25
Me either.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Mar 2008 21:24
Rub a couple of brain cells together, create a spark. Coding puzzles like this are good for all sorts of situations. The answer, I'm sure, is in multiple recursive functions.
Aertic
17
Years of Service
User Offline
Joined: 2nd Jul 2007
Location: United Kingdom
Posted: 28th Mar 2008 21:27
Yeah, but I may have DBP and never used it, not to mention installed it, yet to mention read them damn books I got, and not to metion I dont care about it, if I could do this in C# C++ the I will, but I dont know the varibles/actions/commands whatever there called?

But it is a cool idea.
Venge
18
Years of Service
User Offline
Joined: 13th Sep 2006
Location: Iowa
Posted: 28th Mar 2008 22:40
You might be able to do something like that involving factorials. Cycle through all possible combinations of numbers and operators...Man that would be a huge number.

Something along the lines of 6!*4, except you would multiply by 4 for every step to check for each operator...So it would actually be

(6*4)*(5*4)*(4*4)*(3*4)*(2*4)*(1) = 737,280 possible combinations. (I think)


Except you might not use every number, or might use a number twice...Agh.

There are over 100 billion galaxies in our observable universe, each containing up to a trillion stars.

Feeling small yet?
flashing snall
19
Years of Service
User Offline
Joined: 8th Oct 2005
Location: Boston
Posted: 29th Mar 2008 00:38
oo sounds fun... i cant try right now, but i will once i finish my HW...
i dont think it would be easier, but what if DBRPro stared with the anser, anf tried to get to zero... i dont think it makes a difference, but just something to ponder...


This is my WIP, not even ready for a WIP thread yet though.http://smallgroupproductions.com/
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Mar 2008 00:44 Edited at: 29th Mar 2008 00:46
Quote: "or might use a number twice...Agh"


nope, not allowed, each number just once. Although the same number may appear twice.

My next thought is that you need to get over this scenario...

6 + 4 x 3

which could be

(6 + 4) x 3

or

6 + (4 x 3)

Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 29th Mar 2008 09:38
Quick solution:

Add 6 numbers to an array
Randomize the order
Use a for/next loop
Randomly choose +,-,*,/
You can randomly check if / is possible like 50% of the times
You can weight * high when the factors are low
Check to make sure that the result is always 1-999
And at the end you have the random answer

[center]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Mar 2008 15:51
I think you misunderstand. Given the 6 numbers and a final number, you must create a program that can work out if there is a possible answer, and what it is.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 29th Mar 2008 16:06
Ah, that would be far trickier. But what to use it for? I'm no math wiz so this is not for me.

[center]
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 29th Mar 2008 18:34
You have 6 numbers and 4 operators. Best way would probably to write a code that goes through all the possibilities. You should split it up into two separate algorithms. One that makes a list of all the possible combinations of the 6 numbers (you could make it work for other amounts as well). And another one that runs all the combinations of operators.

I have a thought on the number sorter but it's hard to explain in text so try to follow my thoughts with this:

Flip 1st pair:
1234 > 2134

Flip 2nd pair, then 1st pair:
1324 > 3124 : 2314 > 3214

And keep going with the 3rd pair. If my thoughts are correctly this method should work on any amount of numbers, you just have to figure out a nice way of storing them up into a list.

[center]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Mar 2008 18:36
Quote: "But what to use it for?"


http://www.channel4.com/entertainment/tv/microsites/C/countdown/index.html

A legend in British television history. Just ask Ric, he has a website dedicated to one of the panel.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 29th Mar 2008 18:40
For the operators, start by making a an array equally long as the amount of numbers -1 and just count:

111, 211, 311, 411, 121, 221...

The numbers would represent the operators. Run both lists together in a 3rd algorithm.

[center]
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 29th Mar 2008 18:43 Edited at: 29th Mar 2008 18:44
BatVink:
Yes, but if you plan to make problems for the show then using my first solution should be fine. If I understand correctly the participants must use 6 numbers to get to the final one. Can't these just be premade?


Anyway, anyone think my method would work?

[center]
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Mar 2008 18:44 Edited at: 29th Mar 2008 18:46
That's a good way to start DA. It gets trickier as you go, though. For example, you can put operations in brackets. You can also use just 5 numbers, or 4...

Quote: "but if you plan to make problems for the show then using my first solution should be fine"


No, that's not the idea. Sometimes they get a puzzle that they cannot solve. The example I gave earlier was one of them. But with the right program, you can work out whether they should have been able to solve it, or if it was impossible.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 29th Mar 2008 18:55 Edited at: 29th Mar 2008 18:56
6 + 4 x 3
(6 + 4) x 3
6 + (4 x 3)

This is not a problem as you run through all combinations you would get:

6+4 = 10x3 = 30 : (6 + 4) x 3
4x3 = 12+6 = 18 : 6 + (4 x 3)

Thus, running through all combinations of numbers and operators solves this problem.

As for only using a limited amount of the numbers simply take the list of number combination and run each combination through a process where you use 2 up to the final amount of numbers. You can premake lists of various amounts of operators to save processing time.

[center]

Login to post a reply

Server time is: 2024-11-20 02:43:15
Your offset time is: 2024-11-20 02:43:15