Twelve statements: Difference between revisions

→‎{{header|Haskell}}: Added type signatures, applied hlint, hindent.
(→‎{{header|Haskell}}: Added type signatures, applied hlint, hindent.)
Line 1,860:
<lang haskell>import Data.List (findIndices)
 
tf =:: mapM[[Int] (\_-> Bool] -> [1,0[Int]])
tf = traverse (const [1, 0])
wrongness b = findIndices id . zipWith (/=) b . map (fromEnum . ($ b))
statements = [ (==12) . length,
3 ⊂ [length statements-6..],
2 ⊂ [1,3..],
4 → [4..6],
0 ⊂ [1..3],
4 ⊂ [0,2..],
1 ⊂ [1,2],
6 → [4..6],
3 ⊂ [0..5],
2 ⊂ [10,11],
1 ⊂ [6,7,8],
4 ⊂ [0..10]
] where
(s ⊂ x) b = s == (sum . map (b!!) . takeWhile (< length b)) x
(a → x) b = (b!!a == 0) || all ((==1).(b!!)) x
testall s n = [(b, w) | b <- tf s, w <- [wrongness b s], length w == n]
 
wrongness :: [Int] -> [[Int] -> Bool] -> [Int]
main = let t = testall statements in do
wrongness bns ps = findIndices id . (zipWith (/=) b .ns (map (fromEnum . ($ bns)) ps))
putStrLn "Answer"
 
mapM_ print $ t 0
statements :: [[Int] -> Bool]
putStrLn "Near misses"
statements =
mapM_ print $ t 1</lang>
statements = [ (== 12) . length,
, 3 ⊂ [length statements - 6 ..],
, 2 ⊂ [1,3 ..],
, 4 → [4 .. 6],
, 0 ⊂ [1 .. 3],
, 4 ⊂ [0,2 ..],
, 1 ⊂ [1, 2],
, 6 → [4 .. 6],
, 3 ⊂ [0 .. 5],
, 2 ⊂ [10, 11],
, 1 ⊂ [6, 7, 8],
, 4 ⊂ [0 .. 10]
]
] where where
(⊂), (→) :: Int -> [Int] -> [Int] -> Bool
(s ⊂ x) b = s == (sum . map (b !!) . takeWhile (< length b)) x
(a → x) b = (b !! a == 0) || all ((== 1) . (b !!)) x
 
testall :: [[Int] -> Bool] -> Int -> [([Int], [Int])]
testall s n =
[ (b, w)
| b <- tf s
, w <- [wrongness b s]
, length w == n ]
 
main :: IO ()
main =
main = let t = testall statements in do
in do putStrLn "Answer"
mapM_ print $ t 0
putStrLn "Near misses"
mapM_ print $ t 1</lang>
{{out}}
<pre>
9,655

edits