Archived

This topic is now archived and is closed to further replies.

MattCarpenter

"Mind Bender"

Recommended Posts

For a math class at school, we have to figgure out this ''mind bender'' puzzle by next week. Its basically where we have to find out five peoples first & last names, the color of house they live in, what order their houses are in, and what car they drive using about 8 clues that were given to us. I don''t feel like figguring that out (its hard) so Im going to write a simple program that does it =D Btw, theres 4 people total Im kind of stuck on how I''d do this though.. Heres what I have so far: I''d create a structure for each person (each object of the structure would be their first name) example: struc person { LPCTSTR firstname; LPCTSTR lastname; LPCSTR car; LPCSTR housecolor; bool is_male; int house_number; }; What my program would do is go through every possible combination of people''s ''stuff'' and check each combo and make sure that each ''person'' object meets the criteria which will be programmed in also. Once it finds the correct one, it''ll display it for me.. Im stuck on how I''m going to increment (or go through) the combinations :-/ Im thinking maybe I could do something like this (but Im not sure because I don''t know if it''ll work): person personcombo[how_many_ever_combos_of_people_there_are]; [Fill that array with ''person'' objects w/ the values set to every single combination of names, cars, house colors, etc..)] person p1, p2, p3, p4; [Now, think of p1, p2, p3, and p4 as being digits on a digital display of some sort. start out by making p4 the value of personcombo[0], then check to see if thats the correct combo, then make it personcombo[1], and etc... Make it go all the way up to how_many_ever_combos_of_people_there_are, and make it go back to personcombo[0] again. Then, p3 starts out at 0, and p4 goes through the loop again. Then p3 goes up one and p4 goes through the loop again, and etc.. If this makes any senes..] ANyways, you think this idea for looping through the different combos might work? Any problems with this (Will it take FOREVER to work and find the combo? will it use too much RAM?) Thanks

Share this post


Link to post
Share on other sites
On a 1000mhz computer, it won''t take all that long.

There are 5 people and 5 variabels, the first variabel (first name) is defining the person, so it''s actually 5 people and 4 variabels... I think only about 150 options at maximum. Yeah, it should be possible to do this in just a few seconds

It''s just a matter of generating every possible solution one by one, and checking it against 8 if-statements. On average, you will have found a solution to be wrong after 4 if-statements, and there is a 50% change you only need to check half of the generated options before you find the winner. Generating all the options ahead of time might take a bit of memory, but you don''t have to do that. You can simply fill 5 structs with the information, and then inside the loop that fills them check if they are right. If not, continue with generating a new option, if it is right, exit your loop and display the information.

This is quite a novel approach to such a mind bender, I was confronted with one a few weeks ago, and damn I wish I came up with this idea



This is the polish virus. It is not an executable, but if you would kindly format your entire harddrive, we would be happy.

Share this post


Link to post
Share on other sites
Anyone heard this one?
There isthese 4 american soldiers in vietnam, and
some of them are injured, and they have to cross this
bridge in the middle of the night. They only have one flash
light with them, so they have to go in pairs.
Lets call the guys A, B, C and D.
They have to cross the bridge in 17 minutes or less,
because the bridge is rigged to blow.
A is very athletic, he can cross the bridge in 1 minute
B is tired, he can cross it in 2 minutes
C is hurt in the knee, he can do it in 5 minutes
D is almost uncounscient, he can cross the bridge in 10 minutes

Now, they have to go in pairs, and they travell at the
speed of the slowest guy, so if A and C cross, they''ll take
5 minutes, ''cause thats as fast as C can do it. Then A
comes back with the flashlight and takes another person,
and so on, and so on, till they cross the bridge in 17 minutes
or less...

Can you do it? (sorry for the lenghty explanation...)

heres an example (not a solution):

A&B cross the bridge, A returns (3 minutes, (2+1)
A&D cross the bridge, A returns (11 minutes, 10+1)
A&C cross the bridge, end (5 minutes)
total equals 19 minutes, which is 2 minutes longer than
the 17 minutes they have...

if you get the solution, don''t post it right away, give others
the time to think...



[Hugo Ferreira][Positronic Dreams]
Need [3D Artist] & [Sound Designer]
for small project. Contact me plz...
[-NO TO WAR ON IRAQ-]

Share this post


Link to post
Share on other sites
Funny you should mention that pentium3id, I had this very question on a phone interview with microsoft. The answer is actually simple:

First A&B go over, sending 1 back: 2over + 1back = 3
Then C&D go over, sending 2 back: 10over + 2back = 12 15 total
Then A&B go over +2over- > total = 17 mins

That was fun over the phone, let me tell ya.



============================
A guy, some jolt, and a whole lot of code

[edited by - Tyson on March 19, 2003 7:25:40 PM]

[edited by - Tyson on March 19, 2003 7:31:07 PM]

Share this post


Link to post
Share on other sites
quote:

First A&B go over, sending 1 back: 2over + 1back = 3
Then C&D go over, sending 2 back: 10over + 2back = 12 15 total
Then A&B go over +2over- > total = 17 mins



wheee! That''s nice!

- VizOne

Share this post


Link to post
Share on other sites
Pentium3id: keep ''em coming!
That was too easy though

Here''s one:
2 math professors (a, b) are talking.
a: what are the ages of your 3 children?
b: added together, 13
a: ...
b: and the product of their ages is my house number (which you know)
a: need more info
b: the oldest one''s riding her bike outside

So - how old are they? (ages are not non-integral)

Share this post


Link to post
Share on other sites