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 02:22:45 +0000
Graff wrote on Wed, 03 Nov 2004 20:13:05 -0500
>On Nov 3, 2004, at 7:16 PM, Nigel Garvey wrote:
>> 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.
>
> Odd, I just ran your version and my version side-by-side and got pretty
> much the same time for each, about 15 seconds for 10000 shuffles. I'm
> running under a stock AppleScript installation, no extra OSAX and I'm
> running the script from Script Editor.
>
> I wonder why your script took 14% less time than my script when it was run
> in your environment, I can't think of anything offhand that would cause
> that much of a change.
Sorry, Graff. My timings were done in OS 9.2.2. Switching the same
machine over to Jaguar, the difference isn't as marked. 1000 iterations
of your script take about 9.9 seconds whereas for mine it's about 9.5.
You probably wouldn't notice any difference if you were timing them with
'current date'.
Another possible optimisations is to do all the riffles within the
handler rather than calling the handler for each one. This works out at
about 8.7 seconds in my OS X tests:
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 shuffle(theDeck)
set riffles to 7
repeat riffles times
set cut to 52 - (random number from 1 to 51)
set theDeck to 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 repeat
return theDeck
end shuffle
copy sortedDeck to aDeck
set t to GetMilliSec
repeat 1000 times
set aDeck to shuffle(aDeck)
end repeat
((GetMilliSec) - t) / 1000
>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. ;-)
I think I'll forget that. It would probably take longer to do in
practice....
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