Anonymous user
Twelve statements: Difference between revisions
→{{header|Haskell}}: bug fix, change to 1/0 for easier reading, add indices of incorrect answers
(→{{header|Haskell}}: bug fix, change to 1/0 for easier reading, add indices of incorrect answers) |
|||
Line 22:
Extra credit: also print out a table of near misses, that is, solutions that are contradicted by only a single statement.
=={{header|Haskell}}==
Shows answers with 1 for true, followed by list of indices of incorrect elements each set of 1/0s (index is 0-based).
<lang haskell>tf = mapM (\_ -> [True, False])▼
wrongness b = sumbool . zipWith (/=) b . map ($ b)▼
tf (x:xs) = map (1:) s ++ map (0:) s where s = tf xs
wrongness b = map fst . filter snd .
statements = [ (==12) . length,
3 ⊂ [length statements-6..],
2 ⊂ [1,3..],
4 → [4..6],
0 ⊂ [
4 ⊂ [0,2..],
1 ⊂ [1,2],
Line 40 ⟶ 43:
4 ⊂ [0..10]
] where
(⊂) s x = \b -> s == (
(→) a x = \b ->
testall s n = [(b, w) | b <- tf s, w <- [wrongness b s], length w == n]
main = let t
putStrLn "Answer"
mapM_ print $ t 0
putStrLn "Near misses"
mapM_ print $ t 1
{{out}}
<pre>
Answer
(
Near misses
([1,
([1,
([1,
([1,
([1,
([1,
([1,
([1,
([1,
([1,0,0,0,1,0,0,1,0,1,1,1],[11])
([1,0,0,0,1,0,0,1,0,0,1,0],[11])
([1,0,0,0,1,0,0,1,0,0,0,0],[10])
([1,0,0,0,1,0,0,0,0,0,0,0],[7])
([0,0,0,1,0,0,0,1,0,1,1,1],[0])
([0,0,0,0,1,0,0,1,0,1,1,1],[0])
([0,0,0,0,1,0,0,1,0,0,1,0],[0])
</pre>
|