Demo entry 6344802

python

   

Submitted by anonymous on Jan 24, 2017 at 04:34
Language: Python. Code size: 440 Bytes.

import json

board=[]
size=8
def attack(row,col):
	#left=right=col
	for(i,j)in board:
		if row==i:
			return True
		if col==j:
			return True
		if abs(row-i)==abs(col-j):
			return True
	return False	
def plac(row):
	if row>size:
		print board
	else:
		for col in range(1,size+1):
			if not attack(row,col):
				board.append((row,col))
				plac(row+1)
				board.remove((row,col))

if __name__ =="__main__":
	plac(1)

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).