Skip to content

Instantly share code, notes, and snippets.

@Kah0ona
Created March 2, 2015 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kah0ona/15f3663d0b7846d3f9f6 to your computer and use it in GitHub Desktop.
Save Kah0ona/15f3663d0b7846d3f9f6 to your computer and use it in GitHub Desktop.
solve a flippo by using t [2,2,7,1]
import Data.List
t :: [Double] -> [[Char]]
t f =
let
perms = permutations f
opers = [("+", (+)), ("-", (-)), ("*", (*)), ("/" ,(/))]
in
["(((" ++ (show $ truncate a) ++ n1 ++ (show $ truncate b) ++ ")" ++ n2 ++ (show $ truncate c) ++ ")" ++ n3 ++ (show $ truncate d) ++ ")" |
[a ,b ,c ,d ] <- perms,
(n1, op1) <- opers, (n2, op2) <- opers, (n3,op3) <- opers,
(op3 (op2 (op1 a b) c) d) == 24]
allflippos = [[a,b,c,d] | a <- [0..9], b <- [0..9], c <- [0..9], d <-[0..9],
length (t [a,b,c,d]) > 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment