Re: Bridge anyone? [not off topic]
Re: Bridge anyone? [not off topic]
- Subject: Re: Bridge anyone? [not off topic]
- From: Graff <email@hidden>
- Date: Tue, 02 Nov 2004 00:08:29 -0500
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 ...
set deck to {"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"}
set hands to {{}, {}, {}, {}}
repeat with decksize from 52 to 1 by -1
set r to random number from 1 to decksize
set h to decksize mod 4 + 1
set the end of item h of hands to item r of deck
set item r of deck to item decksize of deck
end repeat
set north to item 1 of hands
set east to item 2 of hands
set south to item 3 of hands
set west to item 4 of hands
Subject: Bridge anyone? [not off topic]
Any way to increase the efficiency of this script that deals out a
bridge (or spades, or hearts, etc.) hand?
set the pack to {}
set the terminator to {}
set the cards to {"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"}
set the hand to {{}, {}, {}, {}}
repeat with i from 1 to 52
copy i to the end of the pack
copy 0 to the end of the terminator
end repeat
repeat until the pack is the terminator
repeat with i from 1 to 4
repeat until (count of item i of the hand) is 13
set the card to some item of the pack
if the card is not 0 then
set item card of the pack to 0
tell the hand to copy (item card of the cards) to the end of item
i of the hand
end if
end repeat
end repeat
end repeat
set north to item 1 of the hand
set east to item 2 of the hand
set south to item 3 of the hand
set west to item 4 of the hand
_______________________________________________
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