Re: Bridge anyone? [not off topic]
Re: Bridge anyone? [not off topic]
- Subject: Re: Bridge anyone? [not off topic]
- From: Bernard Bernu <email@hidden>
- Date: Tue, 2 Nov 2004 10:24:35 +0100
A simpler and quicker version :
13,9 seconds (dual 2 gHz G5, running Smile)
Note that with this algorithm, the hands are sorted for free.
script Bridge
property cards : {"AS", "KS", "QS", "JS", "10S", "9S", "8S", "7S", "6S", "5S", "4S", "3S", "2S", ¬
"AH", "KH", "QH", "JH", "10H", "9H", "8H", "7H", "6H", "5H", "4H", "3H", "2H", ¬
"AD", "KD", "QD", "JD", "10D", "9D", "8D", "7D", "6D", "5D", "4D", "3D", "2D", ¬
"AC", "KC", "QC", "JC", "10C", "9C", "8C", "7C", "6C", "5C", "4C", "3C", "2C"}
property new_hands : {}
on NewDeal()
set new_hands to {{}, {}, {}, {}}
set nh to {1, 2, 3, 4}
repeat with c in cards
set h to (contents of some item of nh)
set hi to item h of new_hands
set end of hi to contents of c
if (count hi) is 13 then
set nnh to {}
repeat with k in nh
if (contents of k) is not h then set end of nnh to k
end repeat
set nh to contents of nnh
end if
end repeat
end NewDeal
end script
chrono
repeat 10000 times
tell Bridge to NewDeal()
end repeat
chrono
Bernard
Le 2 nov. 04, à 08:53, Graff a écrit :
On Nov 2, 2004, at 2:04 AM, kai wrote:
On Tue, 02 Nov 2004 00:08:29 -0500, Graff wrote:
About the same speed as my version, 10000 shuffles on my machine takes 37 seconds for yours, 37 for mine, 75 for Michelle's.
(dual 2 gHz G5, running in Script Editor with no other windows open)
- Ken
On Nov 1, 2004, at 10:40 PM, Tim Mansour wrote:
I haven't timed this Michelle, but my two cents worth is a technique I used to use on a HP programmable calculator once upon a time ...
Some nifty shuffling routines there from Ken and Tim - which I've 'borrowed' from here:
-----------
script deck
property cards : {"AS", "KS", "QS", "JS", "10S", "9S", "8S", "7S", "6S", "5S", "4S", "3S", "2S", "AH", "KH", "QH", "JH", "10H", "9H", "8H", "7H", "6H", "5H", "4H", "3H", "2H", "AD", "KD", "QD", "JD", "10D", "9D", "8D", "7D", "6D", "5D", "4D", "3D", "2D", "AC", "KC", "QC", "JC", "10C", "9C", "8C", "7C", "6C", "5C", "4C", "3C", "2C"}
end script
repeat with n from 1 to 52
set r to random number from 1 to 52
set rItem to item r of deck's cards
set nItem to item n of deck's cards
set item r of deck's cards to nItem
set item n of deck's cards to rItem
end repeat
set north to items 1 thru 13 of deck's cards
set east to items 14 thru 26 of deck's cards
set south to items 27 thru 39 of deck's cards
set west to items 40 thru 52 of deck's cards
-----------
Also not timed, because I'm out of time. Thanks for the exercise, Michelle. G'night, folks. :-)
That speeds things up a bit, 10000 shuffles now take 25 seconds verses 37 for my shuffle.
- Ken
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
________________________________________________________________________
Bernard Bernu | Internet : email@hidden.
Physique Theorique des Liquides | http://www.lptl.jussieu.fr/users/bernu
4, place Jussieu, Tour 16, Et. 5 | Tel : (33) 01 44 27 72 38
Boite 121 | Fax : (33) 01 44 27 51 00
75252 Paris Cedex 05, France
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
________________________________________________________________________
Bernard Bernu | Internet : email@hidden.
Physique Theorique des Liquides | http://www.lptl.jussieu.fr/users/bernu
4, place Jussieu, Tour 16, Et. 5 | Tel : (33) 01 44 27 72 38
Boite 121 | Fax : (33) 01 44 27 51 00
75252 Paris Cedex 05, France
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden