Re: Bridge anyone? [not off topic]
Re: Bridge anyone? [not off topic]
- Subject: Re: Bridge anyone? [not off topic]
- From: Nigel Garvey <email@hidden>
- Date: Thu, 4 Nov 2004 00:16:34 +0000
Graff wrote on Wed, 03 Nov 2004 12:43:17 -0500:
>Well here's a more traditional method for shuffling a deck: cutting and
>riffling. Basically this cuts the deck at a random point, places the
>bottom cut on the top and then splits the deck into two equal halves
>and interleaves them. According to most of the literature the deck
>will be random after 7 riffles. I get 10000 shuffles in 15 seconds for
>this unoptimized script on my dual 2gHz G5. Anyone care at taking a
>crack at optimizing this to see if it can get faster?
On my system, 1000 of your 7-riffle shuffles take about 35 seconds. In
the following version, they take about 30. It doesn't physically "cut the
pack", but works out where each card would have been if it had. I'm not
100% sure I've got the calculation right, but it hasn't errored yet.
I suppose in theory it's possible to calculate where each card would be
after a complete shuffle and only move it then. But that's not for me
tonight. ;-)
set sortedDeck 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"}
on riffle(theDeck)
set cut to 52 - (random number from 1 to 51)
return theDeck's {¬
item ((27 + cut) mod 52 + 1), item ((1 + cut) mod 52 + 1), ¬
item ((28 + cut) mod 52 + 1), item ((2 + cut) mod 52 + 1), ¬
item ((29 + cut) mod 52 + 1), item ((3 + cut) mod 52 + 1), ¬
item ((30 + cut) mod 52 + 1), item ((4 + cut) mod 52 + 1), ¬
item ((31 + cut) mod 52 + 1), item ((5 + cut) mod 52 + 1), ¬
item ((32 + cut) mod 52 + 1), item ((6 + cut) mod 52 + 1), ¬
item ((33 + cut) mod 52 + 1), item ((7 + cut) mod 52 + 1), ¬
item ((34 + cut) mod 52 + 1), item ((8 + cut) mod 52 + 1), ¬
item ((35 + cut) mod 52 + 1), item ((9 + cut) mod 52 + 1), ¬
item ((36 + cut) mod 52 + 1), item ((10 + cut) mod 52 + 1), ¬
item ((37 + cut) mod 52 + 1), item ((11 + cut) mod 52 + 1), ¬
item ((38 + cut) mod 52 + 1), item ((12 + cut) mod 52 + 1), ¬
item ((39 + cut) mod 52 + 1), item ((13 + cut) mod 52 + 1), ¬
item ((40 + cut) mod 52 + 1), item ((14 + cut) mod 52 + 1), ¬
item ((41 + cut) mod 52 + 1), item ((15 + cut) mod 52 + 1), ¬
item ((42 + cut) mod 52 + 1), item ((16 + cut) mod 52 + 1), ¬
item ((43 + cut) mod 52 + 1), item ((17 + cut) mod 52 + 1), ¬
item ((44 + cut) mod 52 + 1), item ((18 + cut) mod 52 + 1), ¬
item ((45 + cut) mod 52 + 1), item ((19 + cut) mod 52 + 1), ¬
item ((46 + cut) mod 52 + 1), item ((20 + cut) mod 52 + 1), ¬
item ((47 + cut) mod 52 + 1), item ((21 + cut) mod 52 + 1), ¬
item ((48 + cut) mod 52 + 1), item ((22 + cut) mod 52 + 1), ¬
item ((49 + cut) mod 52 + 1), item ((23 + cut) mod 52 + 1), ¬
item ((50 + cut) mod 52 + 1), item ((24 + cut) mod 52 + 1), ¬
item ((51 + cut) mod 52 + 1), item ((25 + cut) mod 52 + 1), ¬
item ((52 + cut) mod 52 + 1), item ((26 + cut) mod 52 + 1)}
end riffle
copy sortedDeck to aDeck
set t to GetMilliSec
repeat 1000 times
repeat 7 times
set aDeck to riffle(aDeck)
end repeat
end repeat
((GetMilliSec) - t) / 1000
NG
_______________________________________________
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