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):
>
> ...
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:
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
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
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", ..
On 2007-12-23, Grant Edwards <[EMAIL PROTECTED]> wrote:
> On 2007-12-22, cf29 <[EMAIL PROTECTED]> wrote:
>
>> The goal is to control all the chess board with five queens that do
>> not attack each other.
> [...]
>> My problem starts now. How can I find the next solution and
>> append it to the lis
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)
"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
Sorry again I forgot a part of the function in my previous post:
---
# add nbQueens (5) new queens on safe squares
def newQueens(nbQueens=5):
solution = [] # one solution
for i in range(len(board)): # 64 squares
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
> pro
On Dec 23, 10:18 am, cf29 <[EMAIL PROTECTED]> wrote:
> On Dec 23, 12:39 am, Jervis Liang <[EMAIL PROTECTED]> wrote:
>
> > 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" m
On Dec 23, 12:39 am, Jervis Liang <[EMAIL PROTECTED]> wrote:
> 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 y
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
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
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 queen
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?
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
17 matches
Mail list logo