Re: 5 queens

2007-12-24 Thread cf29
On Dec 23, 2:04 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: def combinations(seq, n):     if n == 0:         yield []     else:         for i in xrange(len(seq)):             for cc in combinations(seq[i+1:], n-1):                 yield [seq[i]]+cc for c in

Re: 5 queens

2007-12-24 Thread Steven D'Aprano
On Mon, 24 Dec 2007 00:18:29 -0800, cf29 wrote: On Dec 23, 2:04 pm, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: def combinations(seq, n):     if n == 0:         yield []     else:         for i in xrange(len(seq)):             for cc in combinations(seq[i+1:], n-1):      

Re: 5 queens

2007-12-24 Thread George Sakkis
On Dec 23, 7:04 am, Steven D'Aprano wrote: def combinations(seq, n): if n == 0: yield [] else: for i in xrange(len(seq)): for cc in combinations(seq[i+1:], n-1): yield [seq[i]]+cc for c in combinations(range(4), 3): ... print c

Re: 5 queens

2007-12-23 Thread cf29
To make it simple and not have to deal with the 8 queens problem that is different with the 5 queens one, I'll ask in a different way. I am not familiar with implementing in Python such terms as standard depth-first search of the solution space, permutation, recursion, 'canonical' form, ... I

Re: 5 queens

2007-12-23 Thread Steven D'Aprano
On Sun, 23 Dec 2007 02:22:38 -0800, cf29 wrote: How would you write a function that will populate a list with a list of numbers with all the possibilities? For example a list of 3 numbers taken among 4 [0,1,2,3] without duplicates. The result should be: [0,1,2] [0,1,3] [0,2,3] [1,2,3]

5 queens

2007-12-22 Thread cf29
Greetings, I designed in JavaScript a small program on my website called 5 queens. (http://www.cf29.com/design/dame5_eng.php) The goal is to control all the chess board with five queens that do not attack each other. I found manually many solutions to this problem (184 until now) and wanted

Re: 5 queens

2007-12-22 Thread Michael Spencer
cf29 wrote: Greetings, I designed in JavaScript a small program on my website called 5 queens. .. Has anyone tried to do a such script? If anyone is interested to help I can show what I've done so far. Tim Peters has a solution to 8 queens in test_generators in the standard library

Re: 5 queens

2007-12-22 Thread John Machin
On Dec 23, 8:05 am, Dennis Lee Bieber [EMAIL PROTECTED] wrote: On Sat, 22 Dec 2007 11:36:07 -0800 (PST), cf29 [EMAIL PROTECTED] declaimed the following in comp.lang.python: Greetings, I designed in JavaScript a small program on my website called 5 queens. Only 5? The classic

Re: 5 queens

2007-12-22 Thread cf29
On Dec 22, 11:05 pm, Dennis Lee Bieber [EMAIL PROTECTED] wrote:         Only 5? The classic algorithm is 8-queens on a standard 8x8 board, as I recall... This is a different problem. You have to control all the squares with only 5 queens. In the 8 queens problem you have to put 8 safe queens. I

Re: 5 queens

2007-12-22 Thread Jervis Liang
On Dec 22, 2:36 pm, cf29 [EMAIL PROTECTED] wrote: The goal is to control all the chess board with five queens that do not attack each other. I found manually many solutions to this problem (184 until now) How did you find 184 solutions? Wolfram says there are 91 distinct solutions for 5

Re: 5 queens

2007-12-22 Thread Fredrik Lundh
Michael Spencer wrote: Tim Peters has a solution to 8 queens in test_generators in the standard library test suite (see: Lib/test/test_generators.py) and for a more straightforward and perhaps more grokkable implementation, see Guido's original Python demo code in Demo/scripts/queens.py

Re: 5 queens

2007-12-22 Thread cf29
solutions? Wolfram says there are 91 distinct solutions for 5-queens on an 8x8 board with no two queens attacking each other. http://mathworld.wolfram.com/QueensProblem.html If I am not mistaken, the 92 solutions are for 8 queens on a 8x8 board with no queen attacking each other. On the same page

Re: 5 queens

2007-12-22 Thread John Machin
to this problem (184 until now) How did you find 184 solutions? Wolfram says there are 91 distinct solutions for 5-queens on an 8x8 board with no two queens attacking each other. http://mathworld.wolfram.com/QueensProblem.html If I am not mistaken, the 92 solutions are for 8 queens

Re: 5 queens

2007-12-22 Thread cf29
On Dec 23, 1:49 am, John Machin [EMAIL PROTECTED] wrote: How did you find 184 solutions? Wolfram says there are 91 distinct solutions for 5-queens on an 8x8 board with no two queens attacking each other. It's *91* distinct solutions to what appears to be *exactly* your problem: k

Re: 5 queens

2007-12-22 Thread cf29
if len(solution) nbQueens:# 5 queens if board[i][2]==0: # free square solution.append(i) # a queen position queenCtrl(board[i]) # the queen controls

Re: 5 queens

2007-12-22 Thread Terry Reedy
John Machin [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] | It's *91* distinct solutions to what appears to be *exactly* your | problem: | | | Dudeney (1970, pp. 95-96) also gave the following results for the | number of distinct arrangements N_u(k,n) of k queens attacking or |

Re: 5 queens

2007-12-22 Thread subeen
Hi, The problem you are trying to solve is a very famous and common problem which can be solved by backtracking. Please try google with 8 queens problem or n queens problem. I designed in JavaScript a small program on my website called 5 queens. (http://www.cf29.com/design/dame5_eng.php

Re: 5 queens

2007-12-22 Thread Grant Edwards
tried to do a such script? ftp://ftp.visi.com/users/grante/python/queens.py It's a pretty standard depth-first search of the solution space. Never mind. I just realized that you said 5-queens, not 8-queens. -- -- http://mail.python.org/mailman/listinfo/python-list

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-17 Thread Tim Roberts
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Background: The problem I'm trying to solve is. There is a 5x5 grid. You need to fit 5 queens on the board such that when placed there are three spots left that are not threatened by the queen. I know this wasn't a contest, but here's my solution

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: The problem I'm trying to solve is. There is a 5x5 grid. You need to fit 5 queens on the board such that when placed there are three spots left that are not threatened by the queen. when you're done with your homework (?), you can compare it with Guido's solution

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread Michael Spencer
Fredrik Lundh wrote: [EMAIL PROTECTED] wrote: The problem I'm trying to solve is. There is a 5x5 grid. You need to fit 5 queens on the board such that when placed there are three spots left that are not threatened by the queen. when you're done with your homework (?), you can compare

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread [EMAIL PROTECTED]
Thank you very much guys! Just for clarification it wasn't homework, just extra credit :) I can't beleive I didn't realize that I didn't clear the GLOBAL variable :D -- http://mail.python.org/mailman/listinfo/python-list

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread Felipe Almeida Lessa
Em Qui, 2006-03-16 às 09:20 +0100, Fredrik Lundh escreveu: when you're done with your homework (?), you can compare it with Guido's solution: http://svn.python.org/view/python/trunk/Demo/scripts/queens.py Just a curiosity. Running the script as the site lists on my computer: $ time

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread [EMAIL PROTECTED]
Sorry to bring this up again, but I decided to try to re-create the program, using the 2d array. However, I ran into a slight problem. How will the permutation function have to be modified? I'm having issues trying to figure out how it works, and how it would need to be modified to use it

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-16 Thread Tim Roberts
Fredrik Lundh [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: The problem I'm trying to solve is. There is a 5x5 grid. You need to fit 5 queens on the board such that when placed there are three spots left that are not threatened by the queen. when you're done with your homework (?), you

Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-15 Thread [EMAIL PROTECTED]
Background: The problem I'm trying to solve is. There is a 5x5 grid. You need to fit 5 queens on the board such that when placed there are three spots left that are not threatened by the queen. My thinking: I created a list, named brd, that represents the board. I made it such that brd[1] would

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-15 Thread Ben Cartwright
[EMAIL PROTECTED] wrote: The first named clearbrd() which takes no variables, and will reset the board to the 'no-queen' position. (snip) The Code: #!/usr/bin/env python brd = [9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] def clearbrd(): brd =

Re: Large algorithm issue -- 5x5 grid, need to fit 5 queens plus some squares

2006-03-15 Thread Lonnie Princehouse
It looks like a good start! Some tips- - Index your arrays starting from 0 instead of 1. It will make life easier (and it's the convention in most modern languages) - Try a two dimensional array for the board representation? A list of lists will do: brd = [ [0] * 5 for i in xrange(5) ]