https://en.wikipedia.org/wiki/Maths24#CombinationsI often play this game by cards game. That means use + - * / and ( ) to calculate four card's number into 24. Just like
For 2,5,5,7=>((2x7)+5)+5
For 5,5,6,6=>((5+5)-6)x6
The rules is Given four number (In a poker game, it can be four cards, A stand for one, 2,3,4,5,6,7,8,9,10 for each number, and J for 11, Q for 12, K for 13), and then Cards are solved by using the numbers, applying only the addition, subtraction, multiplication and division operations to achieve a final mathematical solution of 24.
All four numbers must be included. The numbers can only be used once. No other mathematical operations are allowed.
Yesterday, I wrote some codes to finish it. But I think there are so many clever Lispers in theswamp, so now I post it here and I hope there are many better codes appear.
The challenge:
------------------------------------------------------
(defun c:test (/ lst)
(setq lst (list a b c d))
.......
(princ the solution)
)
--------------------------------------------------------
where a b c d can be any int number or they can be limited to cards game (from 1 to 13).
The results can be duplicate. just like this:
Command: test
a:2
b:3
c:4
d:5
((* (- 5.0 (- 2.0 3.0)) 4.0) . 24.0)
((* (+ (- 3.0 2.0) 5.0) 4.0) . 24.0)
........