Sorry - getting rather chatty, not much J -
your deck, Linda, has faces increasing within decreasing suits, given
that Bridge has the ordering spade > heart > diamond > club ,
so your shuffle produces suits in the "wrong" order.
So redefining deck as (say):
[suits =: |. u: 9824 9829 9830 9827 NB. increasing
♣♦♥♠
faces =: '23456789TJQKA' NB. increasing
|:each (5&{.;_5&{.) deck =:,/suits,"0/faces NB. all increasing
┌─────┬─────┐
│♣♣♣♣♣│♠♠♠♠♠│
│23456│TJQKA│
└─────┴─────┘
NB. for a set of Whist hands: (actually done here with ?. rather than ?)
7 (]<"2 @: {~ \:~"1 @: ((4 , [) ($ ? ~@:#) ])) deck
┌──┬──┬──┬──┐
│♥A│♠K│♠A│♠T│
│♥T│♠4│♠Q│♠5│
│♥2│♦5│♠8│♥J│
│♦T│♦4│♠6│♦9│
│♣Q│♦2│♥K│♦8│
│♣3│♣A│♥7│♣K│
│♣2│♣T│♦J│♣6│
└──┴──┴──┴──┘
Use lh arg of 13 for Bridge Hands.
The down-sort is now intuitive, and we don't need to reverse each column
Cheers,
Mike
On 14/10/2018 16:27, 'Mike Day' via Programming wrote:
Sorry for previous - pressed Send instead of Edit!
Thanks, Linda
No problems under Windows 10 in JQt 807.
I'm no good at Bridge, but might be persuaded to play whist!
If we want to choose Whist or Bridge, we need to specify the
size of a hand. In either case, you can use draw from the row-count
of deck rather than the product of x.
This consideration and some other slight changes lead to:
shuffle =: 13 : '<@|."2 y{~ /:~"1 x$&|. ?~#y'
SO, for a game of Whist:
7 4 shuffle deck
┌──┬──┬──┬──┐
│♣8│♦7│♣6│♦A│
│♣2│♥6│♦Q│♦K│
│♦J│♥5│♦6│♦T│
│♦9│♥4│♥T│♥A│
│♦8│♥3│♥7│♥2│
│♥8│♠Q│♠J│♠K│
│♠4│♠9│♠3│♠8│
└──┴──┴──┴──┘
OR - can't we assume 4 suits? -
7 (13 :'<@|."2 y{~ /:~"1 (4,x)$ ?~#y') deck
┌──┬──┬──┬──┐
│♣A│♦K│♣Q│♣J│
│♣6│♦5│♣2│♣8│
│♦Q│♥K│♦A│♣7│
│♦T│♥Q│♦7│♣3│
│♥A│♥8│♥7│♦J│
│♥2│♥3│♥5│♥6│
│♠7│♠2│♠5│♠Q│
└──┴──┴──┴──┘
Cheers,
Mike
On 14/10/2018 00:47, Linda Alvord wrote:
This should now work in most J environments.
F=:52$'23456789TJQKA'
S=:13#u: 9824 9829 9830 9827
deck=:S,.F
shuf=: 13 :'<"2|."2 y {~ /:~"1 (|.x)$?~*/|.x
Save code above in a file and then run the script.
Here's how it looks in android.
13 4 shuf deck
┌──┬──┬──┬──┐
│♣A│♣J│♣K│♣9│
│♣Q│♣6│♣T│♣3│
│♦K│♣5│♣8│♦A│
│♦T│♣4│♣7│♦J│
│♦9│♣2│♦Q│♦8│
│♦6│♦2│♦7│♥K│
│♥A│♥Q│♦5│♥6│
│♥T│♥J│♦4│♥3│
│♥8│♥9│♦3│♠A│
│♥7│♥4│♠Q│♠K│
│♥5│♥2│♠T│♠9│
│♠8│♠J│♠7│♠6│
│♠5│♠2│♠3│♠4│
└──┴──┴──┴──┘
Linda
Sent from my Verizon, Samsung Galaxy smartphone
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm