Quick write a program which lets you place n queens on an nxn chess board so they can't attack each other. Remember queens can attack in all eight directions.
>>61100207
Hey, it's another >see if /g/ will do your homework thread
summer school already?
Do your homework annon it will help you succeed later on
>>61100328
This
>>61100207
bump
var a=0
var b=0
var c=0
var d=0
var e=0
var f=0
var g=0
var h=0
var s=0;
//generate positions without vertical or horizontal conflict
function GenRows() {
a=Math.floor(Math.random()*7+1);
while(b==0||a==b){b=Math.floor(Math.random()*8+1);}
while(c==0||a==c||b==c){c=Math.floor(Math.random()*8+1);}
while(d==0||a==d||b==d||c==d){d=Math.floor(Math.random()*8+1);}
while(e==0||a==e||b==e||c==e||d==e){e=Math.floor(Math.random()*8+1);}
while(f==0||a==f||b==f||c==f||d==f||e==f){f=Math.floor(Math.random()*8+1);}
while(g==0||a==g||b==g||c==g||d==g||e==g||f==g){g=Math.floor(Math.random()*8+1);}
h=36-a-b-c-d-e-f-g
}
//check output of GenRows for diagonal conflict
function CkDiag() {
if(b==a-1||b==a+1||c==a-2||c==a+2||d==a-3||d==a+3||e==a-4||e==a+4||f==a-5||f==a+5||g==a-6||g==a+6||h==a-7||h==a+7||c==b-1||c==b+1||d==b-2||d==b+2||e==b-3||e==b+3||f==b-4||f==b+4||g==b-5||g==b+5||h==b-6||h==b+6||d==c-1||d==c+1||e==c-2||e==c+2||f==c-3||f==c+3||g==c-4||g==c+4||h==c-5||h==c+5||e==d-1||e==d+1||f==d-2||f==d+2||g==d-3||g==d+3||h==d-4||h==d+4||f==e-1||f==e+1||g==e-2||g==e+2||h==e-3||h==e+3||g==f-1||g==f+1||h==f-2||h==f+2||h==g-1||h==g+1){s=0}else{s=1}
}
//repeat GenRows and CkDiag until valid solution is obtained
while(s==0){
GenRows()
CkDiag()
}
//print answer on page
if(s==1){document.write('HORIZONTAL POSITIONS OF THE QUEENS IN EACH ROW<br>'+a+' '+b+' '+c+' '+d+' '+e+' '+f+' '+g+' '+h+'<br><br>');}
>>61100656
>if(b==a-1||b==a+1||c==a-2||c==a+2||d==a-3||d==a+3||e==a-4||e==a+4||f==a-5||f==a+5||g==a-6||g==a+6||h==a-7||h==a+7||c==b-1||c==b+1||d==b-2||d==b+2||e==b-3||e==b+3||f==b-4||f==b+4||g==b-5||g==b+5||h==b-6||h==b+6||d==c-1||d==c+1||e==c-2||e==c+2||f==c-3||f==c+3||g==c-4||g==c+4||h==c-5||h==c+5||e==d-1||e==d+1||f==d-2||f==d+2||g==d-3||g==d+3||h==d-4||h==d+4||f==e-1||f==e+1||g==e-2||g==e+2||h==e-3||h==e+3||g==f-1||g==f+1||h==f-2||h==f+2||h==g-1||h==g+1){s=0}else{s=1}
>>61100656
This doesn't do n x n boards
Sorry
>>61100207
>>61100207
>Quick write a program which lets you place n queens on an nxn chess board so they can't attack each other. Remember queens can attack in all eight directions.
Technically we only have to print an N by N board. You said "that lets you place" you never said the "program should place" in regards to placing the queens.
Lrn2ritespecsgudfgt
>>61100656
kys idiot
Brotip, there can only be 8 queens.
>>61101011
It's good to be the king.
>>61101149
Correction, >>61100936
There can only be n queens.
My current line of thought is to add queens on varying ends by placing them at L's (the movement of the knight) from each other and then to turn the board around and do the same on the other side. At an L, they're at each other's inaccessible positions.
It's an array indexing problem, inb4 some cunt in Haskell one lines this.
>>61100207
code won't work for certain values of n
The fastest algorithm for this is backtracking. It stops the search immediately as soon as there is a collision. So for example...
Q on A8
QC7
QE6
QG5
QB4
QD3
QF2
Then it as no more valid moves (QH1 is illegal).
So it back traces to the last change-able move. Basically it's like brute force searching, except you instantly eliminate the start of a wrong path.
>>61100328
>fun programming thread
or
>bitter autistic gpu fighting thread no. 99999
hmm
>>61100207
import Data.List
mapIx f= (flip $ zipWith f) [1..]
unique xs=nub xs == xs
diagonal xs = any (not.unique)
[mapIx (+) xs,mapIx (-) xs]
all' n= permutations [1..n]
Queens n=filter (not.diagonal) $ all' n
>>61102163
Brainlet.
First, make a lookup table for every square. Uint64 will suffice for boards not greater than 64 squares, emulate an arbitrary width bitfield for anything else.
Then, it will take n! quick iterations to explore every possibility.
>>61100207
But... there's nothing dynamic about this. You literally can solve this on paper and just have your program output hardcoded data.
Find a permutation s such that for all i and j, |s(i) - s(j)| != |i - j|. Trivial and fast enough for 8 × 8 boards with backtracking.
Now back to the homework board.
>>>/hm/
>>61102375
What you're suggesting is just implementation improvement, not an actual change to the algorithm. Having a lookup table doesn't change which comparisons are done, it just better optimizes the computer. Same for using a bitfield, like here: http://www.cl.cam.ac.uk/~mr10/backtrk.pdf.
All I'm talking about is the optimal algorithm, not the optimal implementation. Hope you enjoyed my autism.
>>61101194
>n queens
No, it's n-1 queens.
It's impossible to place 2 queens in 2x2, 3 queens in 3x3 and 4 in 4x4.
So the solution is (n-1) queens can be placed on an nxn board, which makes things very simple. >>61100207 doesn't have a solution for n queens, thus the task is b8 or retarded.
>>61104366
http://dl.acm.org/citation.cfm?id=122322
Search hill climbing n queens
>>61102547
The same way you can sum all primes under 200000
>>61104954
an 8x8 board can hold 8 queens???
Obviously certain n it wont work.
something something bruteforce sucks something something bitboards and genetic algorithm
do your own homework
>>61100656
>if(b==a-1||b==a+1||c==a-2||c==a+2||d==a-3||d==a+3||e==a-4||e==a+4||f==a-5||f==a+5||g==a-6||g==a+6||h==a-7||h==a+7||c==b-1||c==b+1||d==b-2||d==b+2||e==b-3||e==b+3||f==b-4||f==b+4||g==b-5||g==b+5||h==b-6||h==b+6||d==c-1||d==c+1||e==c-2||e==c+2||f==c-3||f==c+3||g==c-4||g==c+4||h==c-5||h==c+5||e==d-1||e==d+1||f==d-2||f==d+2||g==d-3||g==d+3||h==d-4||h==d+4||f==e-1||f==e+1||g==e-2||g==e+2||h==e-3||h==e+3||g==f-1||g==f+1||h==f-2||h==f+2||h==g-1||h==g+1){s=0}else{s=1}
>>61105463
Show me a 8x8 board with 8 queens. I can't seem to find the positions of queens on anything other than 5x5.
>>61105597
https://youtu.be/jPcBU0Z2Hj8?t=4m10s
Just bruteforce it, dude : ^)
>>61105632
>using the smiley with a carat nose
>>61106045
>commenting on other peoples usage of the smiley with a carat nose
>>61105545
genetic algorithms are dogshit for this problem
>>61106208
If you seek legitimate potty training service, contact [email protected] ...dude's a pooing guru, involved with pooing in loos, hacked into my ex's loo and scrotum, what let me knowing she was streetshitter and also gave my nephew some really outstanding poo scores which he upgraded himself, cool way to have pooing freedom as well. Get your loo-pooing atm cards which could debit money from any a.t.m machine. Make $20,000 and more in a couple loo visits. Poo transfers and loo transfers as well as poo-in-loo jobs, hes that good, had to make him my personal pooer. You could mail him as well if you got issues, he's as discreet and professional too. He's kinda picky though so make mention of the reference.........
cout<<"Go away regard, C++ is superior";