473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

please tell the code of tht puzzle using arrays n strings

1
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 1699
Silent1Mezzo
208 100+
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 Expert 512MB
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 Expert 512MB
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
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...
11
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...
5
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;...
25
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
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...
33
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...
4
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...
9
by: FERHAT AÇICI | last post by:
hi all! who know arrays on visual basic please tell me.... thanks..
22
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.