The 24 Point Game is a classic puzzle game played with playing cards. The rules of the game are as follows: Remove the Jokers from a deck of playing cards, leaving 52 cards, randomly draw 4 cards, and use the numbers on the cards (where J, Q, K, A represent 11, 12, 13, 1 respectively) in combination with addition, subtraction, multiplication, division, and parentheses to achieve a result of 24. Each card must be used once and only once.
Write code to calculate 24 for any given four cards, outputting the solution in text format.
A1 sets the four cards to be used for calculation, B1 enumerates all possible permutations for the four cards, and C1 lists the available arithmetic operators.
Since three operators need to be placed between the four cards, and each can be chosen arbitrarily, D1 utilizes multi-layer loops to list all possible operator combinations. In SPL, the A.conj@r() function, when used at the outermost loop, can union all the results of all layers to a sequence. The results in D1 are as follows:
If you don’t want to manually write the enumeration results in B1, you can generate them using an expression: =4.conj@r(4.(4.(4.([~,get(1),get(2),get(3)]