-- The game of 24 -- Mon Apr 15 7:57:46 CST 2019 -- https://en.wikipedia.org/wiki/24_Game -- https://www.coolmathgames.com/0-make-24 -- https://www.4nums.com/ data Op = Add | Mul | Sub | Div data Exp = Num Int | Bin Op Exp Exp dispatch Add = (+) dispatch Mul = (*) dispatch Sub = (-) dispatch Div = \x y -> if y == 0 || x `mod` y /= 0 then failed else x `div` y permute [] = [] permute (y++[x]++z) = x : permute (y++z) test (Num y) [y] = y test (Bin op x y) (u@(_:_)++v@(_:_)) = (dispatch op) (test x u) (test y v) main | test X (permute problem) == 24 = X where X free problem = [2,3,8,6]