-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImpossibles.hs
executable file
·89 lines (75 loc) · 3.27 KB
/
Impossibles.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
-- This is a Game of Score module that is not currently being used in JS-monads-stable
{-# LANGUAGE OverloadedStrings #-}
module Impossibles where
import Data.List
import System.CPUTime
notWhole :: Double -> Bool
notWhole x = fromIntegral (round x) /= x
cat :: Double -> Double -> Double
cat l m | m < 0 = 3.1
| l == 0 = 3.1
| notWhole l = 3.1
| notWhole m = 3.1
| otherwise = read (show (round l) ++ show (round m))
f :: Double -> String
f x = show (round x)
scoreDiv :: Double -> Double -> Double
scoreDiv az bz | bz == 0 = 99999
| otherwise = (/) az bz
ops :: [Double -> Double -> Double]
ops = [cat, (+), (-), (*), scoreDiv]
calc a b c d e = [ (a',b',c',d') |
[a',b',c',d'] <- nub(permutations [a,b,c,d]),
op1 <- ops,
op2 <- ops,
op2 (op1 a' b') c' == e]
calc2 a b c d e = [ (a',b',c',d') |
[a',b',c',d'] <- nub(permutations [a,b,c,d]),
op1 <- ops,
op2 <- ops,
op2 a' (op1 b' c') == e]
calc3 a b c d e = [ (a',b',c',d') |
[a',b',c',d'] <- nub(permutations [a,b,c,d]),
op1 <- ops,
op2 <- ops,
op3 <- ops,
op3 (op1 a' b') (op2 c' d') == e]
calc4 a b c d e = [ (a',b',c',d') |
[a',b',c',d'] <- nub(permutations [a,b,c,d]),
op1 <- ops,
op2 <- ops,
op3 <- ops,
op3 (op2 (op1 a' b') c') d' == e]
calc5 :: Double -> Double -> Double -> Double -> Double -> [(Double, Double, Double, Double)]
calc5 a b c d e = [ (a',b',c',d') |
[a',b',c',d'] <- nub(permutations [a,b,c,d]),
op1 <- ops,
op2 <- ops,
op3 <- ops,
op3 (op2 a' (op1 b' c')) d' == e]
calc6 a b c d e = [ (a',b',c',d') |
[a',b',c',d'] <- nub(permutations [a,b,c,d]),
op1 <- ops,
op2 <- ops,
op3 <- ops,
op3 a' (op2 (op1 b' c') d') == e]
calc7 a b c d e = [ (a',b',c',d') |
[a',b',c',d'] <- nub(permutations [a,b,c,d]),
op1 <- ops,
op2 <- ops,
op3 <- ops,
op3 a' (op2 b' (op1 c' d')) == e]
impossibles :: Double -> Double -> Double -> Double -> Double -> [[Double]]
impossibles v w x y z = [ [a, b, c, d] | a <- [1..v], b <- [1..w], c <- [1..x], d <- [1..y],
a <= b, b <= c, c <= d,
null $ calc a b c d z, null $ calc2 a b c d z, null $ calc3 a b c d z,
null $ calc4 a b c d z, null $ calc5 a b c d z, null $ calc6 a b c d z,
null $ calc7 a b c d z ]
main = do
t1 <- getCPUTime
let imp = impossibles 6 6 12 20 20
print $ length imp
mapM_ print imp
t2 <- getCPUTime
let t = fromIntegral (t2-t1) * 1e-12
print t