C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Recursion problem - Graph theory - Algorithm needed

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
JimC
Guest





PostPosted: Sat Jan 17, 2004 11:05 am    Post subject: Recursion problem - Graph theory - Algorithm needed Reply with quote



I pose a question here concerning what I think is a classic computer problem,
but I don't know of an algorithm for solving it. It resembles the Towers of
Hanoi prolem.

A few matrices follow. In order to make them more easily understood, it would
be helpful if the reader can disable proportional spacing, although this is not
essential.

Here is the problem. We have a matrix containing elements, represented here
as single upper case letters, and one element with value x. To make this
concrete, let this be the following 4 x 4 matrix in Figure 1:


G B C J
M E O L
x A N D
F H K I

Figure 1

We want to rearrange the elements so that they are ordered beginning with the x
element, followed by the upper-case letters arranged alphabetically, as
shown in Figure 2.


x A B C
D E F G
H I J K
L M N O

Figure 2

But we must use the following rule:

An element can be moved only if it is next to the x element,
in the same row or column, and it must be exchanged with the x element.

So, a possible re-configuration of Figure 1 would be as shown
in Figure 3:



G B C J
M E O L
A x N D
F H K I

Figure 3

where the element with value A in the third row has been exchanged with the
x element to its left.

Does anyone know of an efficient algorithm for producing the steps that
lead to the ordered arrangement in Figure 2?



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Francis Glassborow
Guest





PostPosted: Sat Jan 17, 2004 11:48 pm    Post subject: Re: Recursion problem - Graph theory - Algorithm needed Reply with quote



In message <Co2Ob.2376$IZ1.127 (AT) newssvr29 (DOT) news.prodigy.com>, JimC
<jimc (AT) cross-comp (DOT) com> writes
Quote:
Does anyone know of an efficient algorithm for producing the steps that
lead to the ordered arrangement in Figure 2?

It would help had you actually laid out your matrices so they were
tidily presented with a fixed space font. However putting that aside,
only half of all possible initial arrangements are solvable (you're
problem is the classic 15 blocks problem in a four by four grid with one
empty space. I am sure you will find a reasonable rule for solution in a
suitable book on recreational mathematics.

[Actually on reading the posted problem I realise that I accepted it as
a moderator, without enough consideration. It is not a C++ problem and
so should not have been posted here. My apologies]



--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Jack Klein
Guest





PostPosted: Sun Jan 18, 2004 1:19 am    Post subject: Re: Recursion problem - Graph theory - Algorithm needed Reply with quote



On 17 Jan 2004 06:05:09 -0500, "JimC" <jimc (AT) cross-comp (DOT) com> wrote in
comp.lang.c++.moderated:

Quote:
I pose a question here concerning what I think is a classic computer problem,
but I don't know of an algorithm for solving it. It resembles the Towers of
Hanoi prolem.

[snip]

Quote:
Does anyone know of an efficient algorithm for producing the steps that
lead to the ordered arrangement in Figure 2?

Note that in spite of the moderator's passing it, your question does
not really belong here, or in comp.lang.c++.

There is not a single mention of the C++ language within it anywhere.
You are looking for an algorithm, and algorithms are independent of
C++ or any other programming language.

Your best bet would be to ask this question in a group like
news:comp.programming. Once you have selected an algorithm, if you
have difficulty implementing it correctly in standard C++, posting
your problem code and asking for help in comp.lang.c++ or
comp.lang.c++.moderated would be appropriate.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.