Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46088 > unrolled thread
| Started by | RVic <rvince99@gmail.com> |
|---|---|
| First post | 2013-05-26 10:52 -0700 |
| Last post | 2013-06-01 14:58 +0000 |
| Articles | 20 — 13 participants |
Back to article view | Back to comp.lang.python
Cutting a deck of cards RVic <rvince99@gmail.com> - 2013-05-26 10:52 -0700
Re: Cutting a deck of cards MRAB <python@mrabarnett.plus.com> - 2013-05-26 19:04 +0100
Re: Cutting a deck of cards Kamlesh Mutha <mkamlesh@gmail.com> - 2013-05-26 23:35 +0530
RE: Cutting a deck of cards Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-26 21:16 +0300
Re: Cutting a deck of cards Marc Christiansen <usenetmail@solar-empire.de> - 2013-05-26 21:36 +0200
RE: Cutting a deck of cards Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-26 22:54 +0300
Re: Cutting a deck of cards Marc Christiansen <usenetmail@solar-empire.de> - 2013-05-26 22:13 +0200
Re: Cutting a deck of cards Terry Jan Reedy <tjreedy@udel.edu> - 2013-05-26 17:03 -0400
Re: Cutting a deck of cards RVic <rvince99@gmail.com> - 2013-05-26 11:17 -0700
Re: Cutting a deck of cards Roy Smith <roy@panix.com> - 2013-05-26 14:21 -0400
Re: Cutting a deck of cards Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-05-26 23:17 +0100
RE: Cutting a deck of cards Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-27 01:30 +0300
Re: Cutting a deck of cards Chris Angelico <rosuav@gmail.com> - 2013-05-27 08:42 +1000
RE: Cutting a deck of cards Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-27 01:51 +0300
Re: Cutting a deck of cards Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-05-26 23:56 +0100
Re: Cutting a deck of cards Lee Crocker <leedanielcrocker@gmail.com> - 2013-05-31 04:56 -0700
Re: Cutting a deck of cards Modulok <modulok@gmail.com> - 2013-05-31 12:54 -0600
Re: Cutting a deck of cards Joshua Landau <joshua.landau.ws@gmail.com> - 2013-06-01 18:16 +0100
Re: Cutting a deck of cards Lee Crocker <leedanielcrocker@gmail.com> - 2013-06-01 22:57 -0700
Re: Cutting a deck of cards Giorgos Tzampanakis <giorgos.tzampanakis@gmail.com> - 2013-06-01 14:58 +0000
| From | RVic <rvince99@gmail.com> |
|---|---|
| Date | 2013-05-26 10:52 -0700 |
| Subject | Cutting a deck of cards |
| Message-ID | <4d02f46f-8264-41bf-a254-d1c20469626e@googlegroups.com> |
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
[toc] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2013-05-26 19:04 +0100 |
| Message-ID | <mailman.2183.1369591492.3114.python-list@python.org> |
| In reply to | #46088 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Kamlesh Mutha <mkamlesh@gmail.com> |
|---|---|
| Date | 2013-05-26 23:35 +0530 |
| Message-ID | <mailman.2184.1369591560.3114.python-list@python.org> |
| In reply to | #46088 |
[Multipart message — attachments visible in raw view] — view raw
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 <rvince99@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
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-26 21:16 +0300 |
| Message-ID | <mailman.2186.1369592184.3114.python-list@python.org> |
| In reply to | #46088 |
---------------------------------------- > Date: Sun, 26 May 2013 10:52:14 -0700 > Subject: Cutting a deck of cards > From: rvince99@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) ;)
[toc] | [prev] | [next] | [standalone]
| From | Marc Christiansen <usenetmail@solar-empire.de> |
|---|---|
| Date | 2013-05-26 21:36 +0200 |
| Message-ID | <ar4a7a-cmt.ln1@pluto.solar-empire.de> |
| In reply to | #46094 |
Carlos Nepomuceno <carlosnepomuceno@outlook.com> wrote: > ---------------------------------------- >> Date: Sun, 26 May 2013 10:52:14 -0700 >> Subject: Cutting a deck of cards >> From: rvince99@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
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-26 22:54 +0300 |
| Message-ID | <mailman.2194.1369598093.3114.python-list@python.org> |
| In reply to | #46105 |
---------------------------------------- > From: usenetmail@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?
[toc] | [prev] | [next] | [standalone]
| From | Marc Christiansen <usenetmail@solar-empire.de> |
|---|---|
| Date | 2013-05-26 22:13 +0200 |
| Message-ID | <317a7a-jot.ln1@pluto.solar-empire.de> |
| In reply to | #46109 |
Carlos Nepomuceno <carlosnepomuceno@outlook.com> wrote: > ---------------------------------------- >> From: usenetmail@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
[toc] | [prev] | [next] | [standalone]
| From | Terry Jan Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-05-26 17:03 -0400 |
| Message-ID | <mailman.2201.1369602225.3114.python-list@python.org> |
| In reply to | #46105 |
On 5/26/2013 3:54 PM, Carlos Nepomuceno wrote: > ---------------------------------------- >> From: usenetmail@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.
[toc] | [prev] | [next] | [standalone]
| From | RVic <rvince99@gmail.com> |
|---|---|
| Date | 2013-05-26 11:17 -0700 |
| Message-ID | <db53cc7f-3a99-4e12-84d1-dbd05aeb1e5f@googlegroups.com> |
| In reply to | #46088 |
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]
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2013-05-26 14:21 -0400 |
| Message-ID | <roy-C7646D.14212926052013@news.panix.com> |
| In reply to | #46088 |
In article <4d02f46f-8264-41bf-a254-d1c20469626e@googlegroups.com>, RVic <rvince99@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.
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-05-26 23:17 +0100 |
| Message-ID | <mailman.2210.1369606677.3114.python-list@python.org> |
| In reply to | #46088 |
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: rvince99@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
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-27 01:30 +0300 |
| Message-ID | <mailman.2214.1369607456.3114.python-list@python.org> |
| In reply to | #46088 |
---------------------------------------- > To: python-list@python.org > From: breamoreboy@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
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-05-27 08:42 +1000 |
| Message-ID | <mailman.2217.1369608184.3114.python-list@python.org> |
| In reply to | #46088 |
On Mon, May 27, 2013 at 8:30 AM, Carlos Nepomuceno <carlosnepomuceno@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
[toc] | [prev] | [next] | [standalone]
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Date | 2013-05-27 01:51 +0300 |
| Message-ID | <mailman.2218.1369608693.3114.python-list@python.org> |
| In reply to | #46088 |
---------------------------------------- > Date: Mon, 27 May 2013 08:42:56 +1000 > Subject: Re: Cutting a deck of cards > From: rosuav@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!!!
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-05-26 23:56 +0100 |
| Message-ID | <mailman.2220.1369609207.3114.python-list@python.org> |
| In reply to | #46088 |
On 26/05/2013 23:42, Chris Angelico wrote: > On Mon, May 27, 2013 at 8:30 AM, Carlos Nepomuceno > <carlosnepomuceno@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
[toc] | [prev] | [next] | [standalone]
| From | Lee Crocker <leedanielcrocker@gmail.com> |
|---|---|
| Date | 2013-05-31 04:56 -0700 |
| Message-ID | <4286e1af-f97c-4111-ab3d-cdf2e2fa5fa8@googlegroups.com> |
| In reply to | #46088 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Modulok <modulok@gmail.com> |
|---|---|
| Date | 2013-05-31 12:54 -0600 |
| Message-ID | <mailman.2502.1370026469.3114.python-list@python.org> |
| In reply to | #46599 |
[Multipart message — attachments visible in raw view] — view raw
> 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-
[toc] | [prev] | [next] | [standalone]
| From | Joshua Landau <joshua.landau.ws@gmail.com> |
|---|---|
| Date | 2013-06-01 18:16 +0100 |
| Message-ID | <mailman.2526.1370107013.3114.python-list@python.org> |
| In reply to | #46599 |
On 31 May 2013 12:56, Lee Crocker <leedanielcrocker@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.
[toc] | [prev] | [next] | [standalone]
| From | Lee Crocker <leedanielcrocker@gmail.com> |
|---|---|
| Date | 2013-06-01 22:57 -0700 |
| Message-ID | <2be353cb-d97b-4175-84f2-49c565976325@googlegroups.com> |
| In reply to | #46668 |
>> 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.
[toc] | [prev] | [next] | [standalone]
| From | Giorgos Tzampanakis <giorgos.tzampanakis@gmail.com> |
|---|---|
| Date | 2013-06-01 14:58 +0000 |
| Message-ID | <slrnkqk39p.33c.giorgos.tzampanakis@brilliance.eternal-september.org> |
| In reply to | #46088 |
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/
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web