Simulate random card issuance

 

Four people play poker using a deck of playing cards. After drawing the jokers, the remaining 52 cards are shuffled and divided equally among the four people, with 13 cards per person, sorted by suit and points. Use now ♠,♥,♦,♣ to indicate the suit of playing cards, for example ♠8 represents spades 8, ♥K represents hearts K, please write a program to implement the card issuing process and output 4 sequences.

Firstly, sort the 52 numbers using random numbers, divide them into 4 groups, call the subroutine, pass the current number as a parameter, calculate the corresponding card in the subroutine, and return a card composed of suit and number of points. This process is called the card issuing process.


A

B

1

=52.sort(rand())


2

=A1.group((#-1)\13)


3

=A2.(~.sort().(cardid(~)))

=A3.(~.concat@c())

4



5

func cardid(n)

=mid("KA234567890JQ",1+n%13,1)

6


=mid("♠♥♦♣", (n-1)\13+1,1)

7


return B6+if(B5=="0","10",B5)

http://try.scudata.com.cn/try.jsp?splx=ExA005mnsjfp1.splx

A1 randomly shuffles 52 numbers, rand generates a random number, and sort the sequence randomly.

A2 divides these numbers into 4 groups. Since these numbers are randomly sorted, they can be divided into 4 groups in sequence, with 13 cards in each group. SPL can use A.group(x) to group the members of set A, where x results in the same group, a\b represents integer division, and only the integer part of the result is retained.

A3 loops each person's card group, after sorting, calls the subroutine to convert the number into the corresponding playing card suit and points.

B3 uses concat to represent the cards each person receives as a string, and the result is as follows:

..

A5 defines the subroutine cardid, which takes the number corresponding to the card as the parameter n. When converting, 1~13 represents spades A~K, 14~26 represents hearts A~K, and so on. B5 calculates the number of points in the card, represented by a corresponding character in the string, and specifically, 10 is represented by 0. In SPL, the mid() function can be used to obtain a portion of a string. B6 calculates the suit of the card, also represented by a character in the string. B6 concatenates the suit and points and returns it, converting 0 to 10 here.

When dealing cards, each card will appear, so it is also possible to use a loop to generate the suit and points of each card and then group and sort them without calling subroutines for conversion. For example:


A

1

[,,,]

2

[A,2,3,4,5,6,7,8,9,10,J,Q,K]

3

=A1.conj(A2.(A1.~/~))

4

=52.sort(rand()).group(#%4)

5

=A4.(~.sort().(A3(~)).concat@c())

http://try.scudata.com.cn/try.jsp?splx=ExA005mnsjfp2.splx

A1 and A2 respectively list the suit sequence and point sequence.

A3 loops to calculate each suit, and embed another loop to calculate each point in the former loop to generate the suit and points for each card. Use conj to concatenate the points of each suit into a sequence, as follows:

..

A4 randomly sorts 52 sequence numbers and divides them into 4 groups on average. At this point, the numbering in each group is out of order:

..

A5 sorts the numbers in each group as needed, and then extracts the suit and point of corresponding cards from A3 based on the numbers. As it is a random card issuance, the results in A5 are different from the previous method:

..