Re: Cutting a deck of cards

2013-06-12 Thread Ian Kelly
On Sun, May 26, 2013 at 12:16 PM, Carlos Nepomuceno
carlosnepomuc...@outlook.com wrote:
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)

Not in Python 3.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-06-12 Thread Ian Kelly
On Sun, May 26, 2013 at 12:17 PM, RVic rvinc...@gmail.com wrote:
 Ah, brilliant -- yes, this is so much more elegant in Python:

 #now cut the cards
 x = random.randrange(2,range(13 * 4 * decks))
 cards = cards[x:]+cards[:x]

Or if for some reason you want to do it in place:

cards[x:], cards[:x] = cards[:x], cards[x:]

But note that the order of assignments is subtly important there, so
unless you have a good reason for doing that, it's probably better
just to create a new list for clarity.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Cutting a deck of cards

2013-06-12 Thread Carlos Nepomuceno

 From: usenetm...@solar-empire.de
 Subject: Re: Cutting a deck of cards
 Date: Sun, 26 May 2013 22:13:55 +0200
 To: python-list@python.org

 Carlos Nepomuceno carlosnepomuc...@outlook.com wrote:
 
 From: usenetm...@solar-empire.de
 [...]
 Not in Python3.x
 decks = 6
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)
 False

 What does list(range(13 * 4 * decks)) returns in Python 3?

 A list of course. But Py3 range is very similar to Py2 xrange, it
 returns a range object.

 Adiaŭ
 Marc

What list? '[[0,1,2,...]]' or '[0,1,2,...]'? If it's the later then it's no 
different than what range() returns in Python 2.7.5!
  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Cutting a deck of cards

2013-06-12 Thread Carlos Nepomuceno

 To: python-list@python.org
 From: breamore...@yahoo.co.uk
[...]
 See this
 http://docs.python.org/3/whatsnew/3.3.html#pep-397-python-launcher-for-windows

 --
 If you're using GoogleCrap™ please read this
 http://wiki.python.org/moin/GoogleGroupsPython.

 Mark Lawrence

Piece of cake! So, is there any risk of breaking anything if I install a new 
package after having both Puthon 2 and 3 installed?

How do I choose which one will run the package? Will the package handle the 
settings accordingly or will I need to setup manually?  
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-06-12 Thread Chris Angelico
On Mon, May 27, 2013 at 4:16 AM, Carlos Nepomuceno
carlosnepomuc...@outlook.com wrote:
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)

 ;)

Not in Python 3.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-06-02 Thread Lee Crocker

 and in fact will probably make it worse depending on how you choose
 the cutpoint.
 
 I'm pretty sure it won't. Otherwise you'd be lowering entropy by doing
 a random thing to a random thing.

Doing a random thing to a random thing usually *does* lower entropy when
the random things are actually deterministic algorithms that may have 
unexpected correlations. That's why you don't write your own PRNG unless
you have a very good understanding of the math.

If you are shuffling the deck with, say, numbers from random.org (which uses 
atmospheric noise), then cutting the deck afterward will have precisely 0 
effect, since the (51 * 52!) possible outcomes include 51 copies of each of the 
52! orderings, and so the odds of each end up the same. But if you're choosing 
the cutpoint by getting a value from the same PRNG you used to shuffle, there 
might very well be a correlation that makes some arrangements more likely
than others.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-06-01 Thread Giorgos Tzampanakis
On 2013-05-26, RVic wrote:

 Suppose I have a deck of cards, and I shuffle them

 import random
 cards = []
 decks = 6
 cards = list(range(13 * 4 * decks))
 random.shuffle(cards)

 So now I have an array of cards. I would like to cut these cards at some
 random point (between 1 and 13 * 4 * decks - 1, moving the lower half of
 that to the top half of the cards array.

 For some reason, I can't see how this can be done (I know that it must
 be a simple line or two in Python, but I am really stuck here). Anyone
 have any direction they can give me on this? Thanks, RVic, python newbie


The slice notation should be your friend here:

random.shuffle(cards)
cut_point = random.choice(xrange(len(cards)))
cards = cards[cut_point :] + cards[: cut_point]

-- 
Real (i.e. statistical) tennis and snooker player rankings and ratings:
http://www.statsfair.com/ 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-06-01 Thread Joshua Landau
On 31 May 2013 12:56, Lee Crocker leedanielcroc...@gmail.com wrote:
 Why on Earth would you want to? Cutting a deck makes no sense in software. 
 Randomize the deck properly (Google Fisher-Yates) and start dealing. 
 Cutting the deck will not make it any more random,

True

 and in fact will probably make it worse depending on how you choose the 
 cutpoint.

I'm pretty sure it won't. Otherwise you'd be lowering entropy by doing
a random thing to a random thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-31 Thread Lee Crocker
Why on Earth would you want to? Cutting a deck makes no sense in software. 
Randomize the deck properly (Google Fisher-Yates) and start dealing. Cutting 
the deck will not make it any more random, and in fact will probably make it 
worse depending on how you choose the cutpoint.

The purpose of cutting cards is to make it more difficult for human dealers 
to stack a deck. Simulating it in software makes no more sense than simulating 
the cigars you smoke while playing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-31 Thread Modulok
 Why on Earth would you want to? Cutting a deck makes no sense in
 software. Randomize the deck properly (Google Fisher-Yates) and start
 dealing. Cutting the deck will not make it any more random, and in fact
 will probably make it worse depending on how you choose the cutpoint.

 The purpose of cutting cards is to make it more difficult for human
 dealers to stack a deck. Simulating it in software makes no more sense than
 simulating the cigars you smoke while playing.


Perhaps the OP wanted to study the efficiency and affect of a real-world
shuffling algorithm :-p Maybe he was designing a probabilistic magic trick
and
needed to evaluate how a cut would modify the outcome of a particular stack.
Maybe it was a school assignment. Who knows?

(But yeah if the purpose was for pure randomization then there's no real
point.)

There could be a lot of legitimate reasons though.
-Modulok-
-- 
http://mail.python.org/mailman/listinfo/python-list


Cutting a deck of cards

2013-05-26 Thread RVic
Suppose I have a deck of cards, and I shuffle them

import random
cards = []
decks = 6
cards = list(range(13 * 4 * decks))
random.shuffle(cards)

So now I have an array of cards. I would like to cut these cards at some random 
point (between 1 and 13 * 4 * decks - 1, moving the lower half of that to the 
top half of the cards array.

For some reason, I can't see how this can be done (I know that it must be a 
simple line or two in Python, but I am really stuck here). Anyone have any 
direction they can give me on this? Thanks, RVic, python newbie

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread MRAB

On 26/05/2013 18:52, RVic wrote:

Suppose I have a deck of cards, and I shuffle them

import random
cards = []
decks = 6
cards = list(range(13 * 4 * decks))
random.shuffle(cards)

So now I have an array of cards. I would like to cut these cards at some random 
point (between 1 and 13 * 4 * decks - 1, moving the lower half of that to the 
top half of the cards array.

For some reason, I can't see how this can be done (I know that it must be a 
simple line or two in Python, but I am really stuck here). Anyone have any 
direction they can give me on this? Thanks, RVic, python newbie


The list from its start up to, but excluding, index 'i' is cards[ : i],
and the list from index 'i' to its end is cards[i : ].

Now concatenate them those slices.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Kamlesh Mutha
I guess, you will have to use list slicing mechanism to achieve the desired
result.

Hope this helps,

Cheers,
Kamlesh





On Sun, May 26, 2013 at 11:22 PM, RVic rvinc...@gmail.com wrote:

 Suppose I have a deck of cards, and I shuffle them

 import random
 cards = []
 decks = 6
 cards = list(range(13 * 4 * decks))
 random.shuffle(cards)

 So now I have an array of cards. I would like to cut these cards at some
 random point (between 1 and 13 * 4 * decks - 1, moving the lower half of
 that to the top half of the cards array.

 For some reason, I can't see how this can be done (I know that it must be
 a simple line or two in Python, but I am really stuck here). Anyone have
 any direction they can give me on this? Thanks, RVic, python newbie

 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Faith waiting in the heart of a seed promises a miracle of life which it
can not prove!
-Ravindranath Tagore
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

 Date: Sun, 26 May 2013 10:52:14 -0700
 Subject: Cutting a deck of cards
 From: rvinc...@gmail.com
 To: python-list@python.org

 Suppose I have a deck of cards, and I shuffle them

 import random
 cards = []
 decks = 6
 cards = list(range(13 * 4 * decks))
 random.shuffle(cards)

 So now I have an array of cards. I would like to cut these cards at some 
 random point (between 1 and 13 * 4 * decks - 1, moving the lower half of that 
 to the top half of the cards array.

 For some reason, I can't see how this can be done (I know that it must be a 
 simple line or two in Python, but I am really stuck here). Anyone have any 
 direction they can give me on this? Thanks, RVic, python newbie

 --
 http://mail.python.org/mailman/listinfo/python-list


list(range(13 * 4 * decks)) == range(13 * 4 * decks)

;)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread RVic
Ah, brilliant -- yes, this is so much more elegant in Python:

#now cut the cards
x = random.randrange(2,range(13 * 4 * decks))
cards = cards[x:]+cards[:x]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Roy Smith
In article 4d02f46f-8264-41bf-a254-d1c204696...@googlegroups.com,
 RVic rvinc...@gmail.com wrote:

 Suppose I have a deck of cards, and I shuffle them
 
 import random
 cards = []
 decks = 6
 cards = list(range(13 * 4 * decks))
 random.shuffle(cards)
 
 So now I have an array of cards. I would like to cut these cards at some 
 random point (between 1 and 13 * 4 * decks - 1, moving the lower half of that 
 to the top half of the cards array.
 
 For some reason, I can't see how this can be done (I know that it must be a 
 simple line or two in Python, but I am really stuck here). Anyone have any 
 direction they can give me on this? Thanks, RVic, python newbie

import random
i = random.randrange(len(cards))
cut1 = cards[:i]
cut2 = cards[i:]

I haven't thought too much about the boundary conditions, but that's the 
general idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Marc Christiansen
Carlos Nepomuceno carlosnepomuc...@outlook.com wrote:
 
 Date: Sun, 26 May 2013 10:52:14 -0700
 Subject: Cutting a deck of cards
 From: rvinc...@gmail.com
 To: python-list@python.org

 Suppose I have a deck of cards, and I shuffle them

 import random
 cards = []
 decks = 6
 cards = list(range(13 * 4 * decks))
 random.shuffle(cards)

 So now I have an array of cards. I would like to cut these cards at
 some random point (between 1 and 13 * 4 * decks - 1, moving the lower
 half of that to the top half of the cards array.

 For some reason, I can't see how this can be done (I know that it
 must be a simple line or two in Python, but I am really stuck here).
 Anyone have any direction they can give me on this? Thanks, RVic,
 python newbie

 --
 http://mail.python.org/mailman/listinfo/python-list
 
 
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)
 
 ;)

Not in Python3.x
 decks = 6
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)
False

Adiaŭ
Marc
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

 From: usenetm...@solar-empire.de
[...]
 Not in Python3.x
 decks = 6
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)
 False

 Adiaŭ
 Marc


What does list(range(13 * 4 * decks)) returns in Python 3?
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Marc Christiansen
Carlos Nepomuceno carlosnepomuc...@outlook.com wrote:
 
 From: usenetm...@solar-empire.de
 [...]
 Not in Python3.x
 decks = 6
 list(range(13 * 4 * decks)) == range(13 * 4 * decks)
 False
 
 What does list(range(13 * 4 * decks)) returns in Python 3?  
 

A list of course. But Py3 range is very similar to Py2 xrange, it
returns a range object.

Adiaŭ
Marc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Terry Jan Reedy

On 5/26/2013 3:54 PM, Carlos Nepomuceno wrote:



From: usenetm...@solar-empire.de

[...]

Not in Python3.x

decks = 6
list(range(13 * 4 * decks)) == range(13 * 4 * decks)

False

Adiaŭ
Marc



What does list(range(13 * 4 * decks)) returns in Python 3?  


A list, obviously. What you should ask is what range returns in Python 
3, and you should install python 3 and try it, and list its attributes.




--
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Mark Lawrence

On 26/05/2013 19:16, Carlos Nepomuceno wrote:



Date: Sun, 26 May 2013 10:52:14 -0700
Subject: Cutting a deck of cards
From: rvinc...@gmail.com
To: python-list@python.org

Suppose I have a deck of cards, and I shuffle them

import random
cards = []
decks = 6
cards = list(range(13 * 4 * decks))
random.shuffle(cards)

So now I have an array of cards. I would like to cut these cards at some random 
point (between 1 and 13 * 4 * decks - 1, moving the lower half of that to the 
top half of the cards array.

For some reason, I can't see how this can be done (I know that it must be a 
simple line or two in Python, but I am really stuck here). Anyone have any 
direction they can give me on this? Thanks, RVic, python newbie

--
http://mail.python.org/mailman/listinfo/python-list



list(range(13 * 4 * decks)) == range(13 * 4 * decks)

;)  



Wrong if you're using Python 3 :(

--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

--
http://mail.python.org/mailman/listinfo/python-list


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

 To: python-list@python.org
 From: breamore...@yahoo.co.uk
[...]
 Wrong if you're using Python 3 :(

 --
 If you're using GoogleCrap™ please read this
 http://wiki.python.org/moin/GoogleGroupsPython.

 Mark Lawrence


Thanks guys! I've been delaying my dive into Python 3 (because I don't need it 
for now) but I'd like to run some code just to learn how different it is from 
Python 2 and even other Python flavors.

So, I'd like to know if it's possible to have multiple Python installations on 
the same machine (Windows 7 in my particular case) without messing one with 
each other. What care must I take not to mess up with them?

I've just found this[1] awesome service, but ridiculously it's PHP powered!!! 
lol Come on!!!

Why there aren't more Python powered websites available? What's the catch?


[1] http://www.compileonline.com/execute_python3_online.php 
  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Chris Angelico
On Mon, May 27, 2013 at 8:30 AM, Carlos Nepomuceno
carlosnepomuc...@outlook.com wrote:
 Thanks guys! I've been delaying my dive into Python 3 (because I don't need 
 it for now) but I'd like to run some code just to learn how different it is 
 from Python 2 and even other Python flavors.

 So, I'd like to know if it's possible to have multiple Python installations 
 on the same machine (Windows 7 in my particular case) without messing one 
 with each other. What care must I take not to mess up with them?

Easy. Just grab the standard installer and hit it. You'll get two
separate directories (or more; I have \Python26, \Python27, \Python32,
\Python33 on this box), and you can run whichever you want. The one
thing to take care of is .py associations; I haven't actually done it
(on here, all I actually do is IDLE, pretty much), but as of 3.3, you
should be able to use a Unix-style shebang to indicate which Python
you want to invoke.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Cutting a deck of cards

2013-05-26 Thread Carlos Nepomuceno

 Date: Mon, 27 May 2013 08:42:56 +1000
 Subject: Re: Cutting a deck of cards
 From: ros...@gmail.com
[...]
 Easy. Just grab the standard installer and hit it. You'll get two
 separate directories (or more; I have \Python26, \Python27, \Python32,
 \Python33 on this box), and you can run whichever you want. The one
 thing to take care of is .py associations; I haven't actually done it
 (on here, all I actually do is IDLE, pretty much), but as of 3.3, you
 should be able to use a Unix-style shebang to indicate which Python
 you want to invoke.

 ChrisA

I'm not even using shebangs in Windows because I thought it wouldn't make any 
difference. I'm used to run scripts like python filename.py from the command 
line. No problem!

So, Python 3.3 will honor if I insert #!C:\Python27\python.exe? if I install 
it after Python 2.7? Cool!!!   
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread Mark Lawrence

On 26/05/2013 23:42, Chris Angelico wrote:

On Mon, May 27, 2013 at 8:30 AM, Carlos Nepomuceno
carlosnepomuc...@outlook.com wrote:

Thanks guys! I've been delaying my dive into Python 3 (because I don't need it 
for now) but I'd like to run some code just to learn how different it is from 
Python 2 and even other Python flavors.

So, I'd like to know if it's possible to have multiple Python installations on 
the same machine (Windows 7 in my particular case) without messing one with 
each other. What care must I take not to mess up with them?


Easy. Just grab the standard installer and hit it. You'll get two
separate directories (or more; I have \Python26, \Python27, \Python32,
\Python33 on this box), and you can run whichever you want. The one
thing to take care of is .py associations; I haven't actually done it
(on here, all I actually do is IDLE, pretty much), but as of 3.3, you
should be able to use a Unix-style shebang to indicate which Python
you want to invoke.

ChrisA



See this 
http://docs.python.org/3/whatsnew/3.3.html#pep-397-python-launcher-for-windows


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

--
http://mail.python.org/mailman/listinfo/python-list