To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Article :: Building Dynamic Systems with Expressions in .NET
How Is XML Like An Interface?
Understanding Covariance and Contravariance
Print VS 2010 Keyboard Shortcut References in Letter (8.5x11in) and A4 (210×297mm) Sizes
Updated Productivity Power Tools



Go Back   VBForums > VBForums CodeBank > CodeBank - C++

Reply Post New Thread
 
Thread Tools Display Modes
Old Aug 7th, 2003, 11:41 PM   #1
pradeepkrao
Fanatic Member
 
pradeepkrao's Avatar
 
Join Date: Sep 01
Location: New Jersey
Posts: 534
pradeepkrao is an unknown quantity at this point (<10)
C - 8 Queens Problem

Hi,

I saw a very cryptic code for 8 queens problem in the internet.

Place 8 queens in a chess board such that no other queen is in the same row, column and diagnol.

Code:
# include<stdio.h>
int v,i,j,k,l,s,a[99];
main()
{
for(s=8;*a-s;v=a[j*=v]-a[i],k=i<s,j+=(v=j<s&&(!k&&!!printf(2+"\n\n%c"-(!l<<!j)," #Q"[l^v?(l^j)&1:2])&&++l||a[i]<s&&v&&v-i+j&&v+i-j))&&!(l%=s),v||(i==j?a[i+=k]=0:++a[i])>=s*k&&++a[--i]);
printf("\n\n");
}
My Code
Code:
# include<stdio.h>
# define Q  8
struct POINT {int x,y;}; 
POINT q[Q];
int N;
bool chkAll(int x){
	for ( int i =x ; i >=0 ; i--)
	for(int j = i - 1; j >= 0 ; j--)
	if(q[i].x == q[j].x || q[i].y == q[j].y || 
	   q[i].x + q[i].y == q[j].x + q[j].y || 
	   q[i].x - q[j].x == q[i].y - q[j].y)
	return false; return true;
}
void MoveQueen(int x){
	
	if(x >= Q)
	{	
		printf("\n\nSolution : %d \n\n\t",++N);
		for(int j=0;j<Q;printf("\n\t"),j++)
		for(int i=0;i<Q;((q[j].x==j) && (q[j].y==i))?printf("Q%c",179) : printf("_%c",179),i++);
		return;
	}	
	
	for (int j = 0; j < Q ;q[x].x = x,j++){	q[x].y = j;
		  if(chkAll(x)) MoveQueen(x + 1);
	}
}
void main(){for (int i = 0; i < Q; q[0].x = 0,q[0].y = i,MoveQueen(1),i++);}
Regards,
Pradeep
__________________
Learn by others experience as you cannot live long to experience them all.
www.freewebs.com/pradeepkrao

LOOK AT MY GAMES AT MY WEB SITE.
pradeepkrao is offline   Reply With Quote
Old Sep 16th, 2003, 12:36 PM   #2
CornedBee
Kitten
 
CornedBee's Avatar
 
Join Date: Aug 01
Location: In a microchip!
Posts: 11,594
CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)CornedBee is a glorious beacon of light (400+)
Could you deobfuscate that stuff?
__________________
All the buzzt
CornedBee

"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen

Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
CornedBee is offline   Reply With Quote
Old Sep 16th, 2003, 11:32 PM   #3
pradeepkrao
Fanatic Member
 
pradeepkrao's Avatar
 
Join Date: Sep 01
Location: New Jersey
Posts: 534
pradeepkrao is an unknown quantity at this point (<10)
Hi Cornedbee

Hi,

The code which I found in the internet.. ??????... I have no clue what it does but when compiled runs like a charm...

The problem is place 8 queens on a chess board in such a way that no other queen falls in the same diagnoal and verticle and horizontal.

Check my games section in my website, I have made that game in VB, there is a cheat code also which will give you the list of solutuions...

Regards,
Pradeep
__________________
Learn by others experience as you cannot live long to experience them all.
www.freewebs.com/pradeepkrao

LOOK AT MY GAMES AT MY WEB SITE.
pradeepkrao is offline   Reply With Quote
Old Apr 30th, 2005, 08:51 AM   #4
tonyrueb
Member
 
Join Date: Jan 05
Location: Minnesota
Posts: 46
tonyrueb is an unknown quantity at this point (<10)
Re: C - 8 Queens Problem

The program works great!! Just one thing, can you put comments on your code. i am trying to learn how to program and it would really help me out.
tonyrueb is offline   Reply With Quote
Reply

Go Back   VBForums > VBForums CodeBank > CodeBank - C++


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:06 PM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.