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: Tue, 2 Nov 2004 20:27:49 +0000
Bernard Bernu wrote on 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
And of course that handler can be optimised still further: :-)
on NewDeal()
set new_hands to {{}, {}, {}, {}}
set nh to {1, 2, 3, 4}
repeat with c in cards
set h to (some integer 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 item h of nh to missing value
end repeat
end NewDeal
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