Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Not Equal to Each Other?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
ale.of.gin...@gmail.com  
View profile  
 More options Nov 3 2005, 8:01 pm
Newsgroups: comp.lang.python
From: ale.of.gin...@gmail.com
Date: 3 Nov 2005 17:01:08 -0800
Local: Thurs, Nov 3 2005 8:01 pm
Subject: Not Equal to Each Other?
Another question:  I am writing a sudoku solving program.  The
'solving' part of is just multiple iterations.  It will take random
numbers and keep switching it all around until a set of logic
statements has been met (ie; all numbers in a row are not equal to each
other) ... that's where my question comes in.

Cellboard = my list for storing each row/column's data.

Rather than writing

cellboard[0] is not* (cellboard[1] and cellboard[2] and cellboard[3]
and cellboard[4] ... cellboard[8])
cellboard[1] is not (cellboard[0] and cellboard[2] and cellboard[3] and
cellboard[4] ... cellboard[8])
etc...

* should this be != ?

the above so that all the data in one row is not equal to each other,
is there something I can write to make it simpler?  For example,
(cellboard[0] is not cellboard[1] is not ... cellboard[8]) only worked
for the numbers to the left and right of the cell - is there anyway I
can expand this to cover all numbers in a set range?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stephen Thorne  
View profile  
 More options Nov 3 2005, 9:00 pm
Newsgroups: comp.lang.python
From: Stephen Thorne <stephen.tho...@gmail.com>
Date: Fri, 4 Nov 2005 12:00:32 +1000
Local: Thurs, Nov 3 2005 9:00 pm
Subject: Re: Not Equal to Each Other?
On 3 Nov 2005 17:01:08 -0800, ale.of.gin...@gmail.com

<ale.of.gin...@gmail.com> wrote:
> the above so that all the data in one row is not equal to each other,
> is there something I can write to make it simpler?  For example,
> (cellboard[0] is not cellboard[1] is not ... cellboard[8]) only worked
> for the numbers to the left and right of the cell - is there anyway I
> can expand this to cover all numbers in a set range?

Python has an operator call 'in', which will allow you to do what you're after.

"1 in (1,2,3)" will be true
"4 in (1,2,3)" will be false
"not 1 in (1,2,3)" will be false

So you'd be after something along the lines of:
not cellboard[0] in (cellboard[1], ...., celboard[8]).

This seems quite tedious to write, maybe you should consider something
along the lines of using slicing:

not celboard[0] in cellboard[1:8]

I hope i have given you enough tools to do what you're trying to do.

--
Stephen Thorne
Development Engineer


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alex Martelli  
View profile  
 More options Nov 3 2005, 9:42 pm
Newsgroups: comp.lang.python
From: al...@mail.comcast.net (Alex Martelli)
Date: Thu, 3 Nov 2005 18:42:34 -0800
Local: Thurs, Nov 3 2005 9:42 pm
Subject: Re: Not Equal to Each Other?
<ale.of.gin...@gmail.com> wrote:

   ...

> Rather than writing

> cellboard[0] is not* (cellboard[1] and cellboard[2] and cellboard[3]
> and cellboard[4] ... cellboard[8])
> cellboard[1] is not (cellboard[0] and cellboard[2] and cellboard[3] and
> cellboard[4] ... cellboard[8])

Urgh... the fastest way to check that a list of N numbers has no
duplicates is:
    if len(set(thelist)) == len(thelist):
        print 'no duplicates'

But if your purpose is to generate N random samples out of a population
of M, look at function random.sample (in module random in the Pythons
standard library) and you'll do even better!-)

Alex


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ale.of.gin...@gmail.com  
View profile  
 More options Nov 3 2005, 10:03 pm
Newsgroups: comp.lang.python
From: ale.of.gin...@gmail.com
Date: 3 Nov 2005 19:03:03 -0800
Local: Thurs, Nov 3 2005 10:03 pm
Subject: Re: Not Equal to Each Other?
For the

not cellboard[0] in cellboard[1:8] (I knew about ranges/slicing using a
colon, can't believe I didn't think of that!)

line, will I have to write that out for each number?

So the line:

not cellboard in ((cellboard[1:8]) and (cellboard[9] and cellboard[18]
and cellboard[27] and cellboard[36] and cellboard[45] and cellboard[54]
and cellboard[63] and cellboard[72]) and (cellboard[1:2] and
cellboard[9:11] and cellboard[18:20]))

will cover all the logic requirements for the number in cell 0 (well,
row 1, column 1).

But will I have to copy + paste + edit that for all 81 cells?  That
isn't complicated, just tedious - thanks though.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bengt Richter  
View profile  
 More options Nov 3 2005, 10:08 pm
Newsgroups: comp.lang.python
From: b...@oz.net (Bengt Richter)
Date: Fri, 04 Nov 2005 03:08:05 GMT
Local: Thurs, Nov 3 2005 10:08 pm
Subject: Re: Not Equal to Each Other?
On 3 Nov 2005 17:01:08 -0800, ale.of.gin...@gmail.com wrote:

UIAM if you have a list of items that are comparable and hashable, like integers,
you can make a set of the list, and duplicates will be eliminated in the set.
Therefore if the resulting set has the same number of members as the list it
was made from, you can conclude that the list contains no duplicates. E.g.,

 >>> cellboard = range(8)
 >>> cellboard
 [0, 1, 2, 3, 4, 5, 6, 7]
 >>> set(cellboard)
 set([0, 1, 2, 3, 4, 5, 6, 7])
 >>> len(set(cellboard))
 8
 >>> cellboard[2] = 7
 >>> cellboard
 [0, 1, 7, 3, 4, 5, 6, 7]
 >>> set(cellboard)
 set([0, 1, 3, 4, 5, 6, 7])
 >>> len(set(cellboard))
 7

So the test would be
 >>> len(set(cellboard))==len(cellboard)
 False
And after repairing the list to uniqueness of elements:
 >>> cellboard[2] = 2
 >>> len(set(cellboard))==len(cellboard)
 True

HTH

Regards,
Bengt Richter


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ale.of.gin...@gmail.com  
View profile  
 More options Nov 4 2005, 7:30 am
Newsgroups: comp.lang.python
From: ale.of.gin...@gmail.com
Date: 4 Nov 2005 04:30:44 -0800
Local: Fri, Nov 4 2005 7:30 am
Subject: Re: Not Equal to Each Other?
How do I 'define' set?  Is there something to include (like import
random)?

while (choice == 3) and len(set(cellboard[0:8]))==len(cellboard[0:8]):
        # DEFINE TWO RANDOM VARIABLES (ONE FOR ARRAY, ONE FOR NUMBER
VALUE)
        solvingrandom = random.randint(1,9)
        cellboardrandom = random.randint(0,8)
        set(cellboard[0:8])

        # CHECK TO MAKE SURE THE RANDOMLY ASSIGNED CELL DOES NOT HAVE A
VALUE
        if (cellboard[cellboardrandom] is not ('1' or '2' or '3' or '4'
or '5' or '6' or '7' or '8' or '9')):
            cellboard[cellboardrandom] = solvingrandom

The above is my code (right now it will only work for the first row's
numbers).  Anything else I need to add?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Juho Schultz  
View profile  
 More options Nov 4 2005, 8:16 am
Newsgroups: comp.lang.python
From: Juho Schultz <juho.schu...@helsinki.fi>
Date: Fri, 04 Nov 2005 15:16:26 +0200
Local: Fri, Nov 4 2005 8:16 am
Subject: Re: Not Equal to Each Other?
ale.of.gin...@gmail.com wrote:
> How do I 'define' set?  Is there something to include (like import
> random)?

set is a built-in type in Python 2.4
If you use 2.3 you can use the sets module with "import sets"

Simplify your code a bit:

'2' is not ('1' or '2' or '3' or '4' or '5' or '6' or '7' or '8' or '9')
evaluates to True
'1' is not ('1' or '2' or '3' or '4' or '5' or '6' or '7' or '8' or '9')
evaluates to False
Somehow I do not believe you want that behavipur.

If cellboard contains characters, you could use:
if (cellboard[cellboardrandom] not in '123456789')

for integers, the following should work:
if not (1 <= cellboard[cellboardrandom] <= 9)

Using None to code empty cells, you could even have:
if (cellboard[cellboardrandom] is None)


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
jgardner@jonathangardner. net  
View profile  
 More options Nov 4 2005, 11:03 am
Newsgroups: comp.lang.python
From: "jgard...@jonathangardner.net" <jgard...@jonathangardner.net>
Date: 4 Nov 2005 08:03:01 -0800
Local: Fri, Nov 4 2005 11:03 am
Subject: Re: Not Equal to Each Other?

>  will I have to write that out for each number?

Not if you know how to use the 'for' statement. It will allow you to
iterate through the rows or columns or whatnot.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google