473,657 Members | 2,545 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

please tell the code of tht puzzle using arrays n strings

1 New Member
Problem statement:
You might have come across a puzzle which contains 15 numbered square pieces, which can be moved horizontally or vertically. A possible arrangement of these pieces is shown below:

11 43 15 76
87 120 12 1
66 22 43 4
21 89 93

As you can see, there is a blank at the bottom right corner. Implement the following program:
Numbers should be displayed in the above fashion. Allow the user to hit any of the arrow keys (up, down, left or right). If user hits up key, then the pieces with number 4 and blank piece will be swapped, and this table will look like

11 43 15 76
87 120 12 1
66 22 43
21 89 93 4

After that if user hits left key, then the piece with number 93 and blank piece will be swapped and table will look like:

11 43 15 76
87 120 12 1
66 22 43
21 89 93 4

If user hits left key and there is no column on left, then it should give appropriate message, which shows that it can’t move this side. With every hit, it will check whether numbers are sorted in ascending order or not. When all 15 integers are sorted and blank is at last position, then it should stop by giving success message, and this table will look like:

1 4 11 12
15 21 22 43
43 66 76 87
89 93 120
To keep track of keys, use getch ( ) and identify each key by its codes as follows:

• Up arrow key: 72
• Down arrow key: 80
• Right arrow key: 75
• Left arrow key: 77

It should also show number of moves at each step. It may also be stopped by press ‘q’ somewhere to quit the program.
Jun 4 '07 #1
3 1730
Silent1Mezzo
208 New Member
Please don't post questions right out of a text book.

Start this on you're own and then come here for help once you have a question about coding.
Jun 4 '07 #2
ilikepython
844 Recognized Expert Contributor
Problem statement:
You might have come across a puzzle which contains 15 numbered square pieces, which can be moved horizontally or vertically. A possible arrangement of these pieces is shown below:

11 43 15 76
87 120 12 1
66 22 43 4
21 89 93

As you can see, there is a blank at the bottom right corner. Implement the following program:
Numbers should be displayed in the above fashion. Allow the user to hit any of the arrow keys (up, down, left or right). If user hits up key, then the pieces with number 4 and blank piece will be swapped, and this table will look like

11 43 15 76
87 120 12 1
66 22 43
21 89 93 4

After that if user hits left key, then the piece with number 93 and blank piece will be swapped and table will look like:

11 43 15 76
87 120 12 1
66 22 43
21 89 93 4

If user hits left key and there is no column on left, then it should give appropriate message, which shows that it can’t move this side. With every hit, it will check whether numbers are sorted in ascending order or not. When all 15 integers are sorted and blank is at last position, then it should stop by giving success message, and this table will look like:

1 4 11 12
15 21 22 43
43 66 76 87
89 93 120
To keep track of keys, use getch ( ) and identify each key by its codes as follows:

• Up arrow key: 72
• Down arrow key: 80
• Right arrow key: 75
• Left arrow key: 77

It should also show number of moves at each step. It may also be stopped by press ‘q’ somewhere to quit the program.
We don't "tell" the code to someone. We help them with their problems. Post a clear and specific question and we will help you.
Jun 4 '07 #3
ilikepython
844 Recognized Expert Contributor
Please don't post questions right out of a text book.

Start this on you're own and then come here for help once you have a question about coding.
Ah you beat me to it...
Jun 4 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
1443
by: Jerry Coffin | last post by:
Jerry Coffin wrote: > > > Q7 Remove duplicates in array > > > > You can't really "remove" an element from an array, so this is poorly > > defined. If it was a C++ vector (for example) std::sort and > > std::unique would render it trivial, as would inserting the elements > > into an std::set, and then copying them back out. Doing it quickly > > while retaining the original order is a little more challenging. > How can you _not_ remove...
11
3530
by: Lues | last post by:
Hi, I'm trying to protect some data in tables with encription (you know why, don't you ;)) I must confess that I'm not very expirienced in writing code, especially encription code. Can any one, please , send VB code for access which I can c/p into one function. It don't have to be RSA, it can be anything which is easy to
5
1556
by: cpptutor2000 | last post by:
I am compiling and running the following code snippet on a Linux box - I am really puzzled by the answers. Could someone please tell me what might be wrong? void test(){ int m = 0; int n = 0; int i = 0; int j = 0;
25
1485
by: nichas | last post by:
what does this part of the code mean.. iam not getting it.. ............ typedef int RowArray; RowArray *rptr; ............... i didnt get this.. please reply fast...thank you.
4
1048
by: J M | last post by:
Hi, I'm working on a program that writes data to a DOS-file (a file that is to be read by a DOS-program), thus using codepage 437. When writing to a binary file there was no problem at all, I just used GetEncoder(437) to write the byte arrays to the file. But I also have to write to a sequential file. WriteLine doesn't support byte arrays. I ended up first encoding the strings to byte arrays, writing them to a binary file, opening that...
33
2851
by: Martin Jørgensen | last post by:
Hi, In continuation of the thread I made "perhaps a stack problem? Long calculations - strange error?", I think I now got a "stable" error, meaning that the error always seem to come here now (tried: visual studio 2005 + linux/macintosh gcc)... That's a pretty good thing. I think the error still appears using both gcc and visual studio 2005. Everything is standard C (ANSI C ?? I don't know the difference) - but since so many functions...
4
2422
by: k04jg02 | last post by:
I was thinking that it would be cool if a programming language could implement an array type in its standard library rather than depending on arrays being a builtin type. I wondered if C++ could do this. Obviously, writing a class that just used a C array under the hood would be cheating. As would simply allocating a big chunk of memory on the heap -- for it to be a true equivalent of a C array it should be allocate memory on the stack. ...
9
1974
by: FERHAT AÇICI | last post by:
hi all! who know arrays on visual basic please tell me.... thanks..
22
3253
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of seats as 0 and the flight no. is also repeating. If any can tell why is this please help me. #include<stdio.h> #include<ctype.h> #include<conio.h>
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1953
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1611
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.