Twelve statements: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: bug fix, change to 1/0 for easier reading, add indices of incorrect answers) |
|||
Line 24: | Line 24: | ||
Shows answers with 1 for true, followed by list of indices of incorrect elements each set of 1/0s (index is 0-based). |
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> |
<lang haskell>import Data.List (findIndices) |
||
tf (x:xs) = map (1:) s ++ map (0:) s where s = tf xs |
|||
tf = mapM (\_ -> [1,0]) |
|||
wrongness b = |
wrongness b = findIndices id . zipWith (/=) b . map (fromEnum . ($ b)) |
||
zip [0..] . zipWith (/=) b . map (\f ->fromEnum $ f b) |
|||
statements = [ (==12) . length, |
statements = [ (==12) . length, |
||
Line 43: | Line 43: | ||
4 ⊂ [0..10] |
4 ⊂ [0..10] |
||
] where |
] 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] |
testall s n = [(b, w) | b <- tf s, w <- [wrongness b s], length w == n] |