Twelve statements: Difference between revisions
Content deleted Content added
→{{header|Haskell}}: bug fix, change to 1/0 for easier reading, add indices of incorrect answers |
|||
Line 22: | Line 22: | ||
Extra credit: also print out a table of near misses, that is, solutions that are contradicted by only a single statement. |
Extra credit: also print out a table of near misses, that is, solutions that are contradicted by only a single statement. |
||
=={{header|Haskell}}== |
=={{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). |
|||
⚫ | |||
sumbool = length . filter id |
|||
⚫ | |||
⚫ | |||
tf (x:xs) = map (1:) s ++ map (0:) s where s = tf xs |
|||
wrongness b = map fst . filter snd . |
|||
⚫ | |||
statements = [ (==12) . length, |
statements = [ (==12) . length, |
||
3 ⊂ [length statements-6..], |
3 ⊂ [length statements-6..], |
||
2 ⊂ [1,3..], |
2 ⊂ [1,3..], |
||
4 → [4..6], |
4 → [4..6], |
||
0 ⊂ [ |
0 ⊂ [1..3], |
||
4 ⊂ [0,2..], |
4 ⊂ [0,2..], |
||
1 ⊂ [1,2], |
1 ⊂ [1,2], |
||
Line 40: | Line 43: | ||
4 ⊂ [0..10] |
4 ⊂ [0..10] |
||
] where |
] where |
||
(⊂) s x = \b -> s == ( |
(⊂) s x = \b -> s == (sum . map (b!!) . takeWhile (< length b)) x |
||
(→) a x = \b -> |
(→) 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] |
|||
main = let t |
main = let t = testall statements in do |
||
putStrLn "Answer" |
putStrLn "Answer" |
||
mapM_ print $ t 0 |
mapM_ print $ t 0 |
||
putStrLn "Near misses" |
putStrLn "Near misses" |
||
mapM_ print $ t 1 |
mapM_ print $ t 1</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Answer |
Answer |
||
( |
([1,0,1,1,0,1,1,0,0,0,1,0],[]) |
||
Near misses |
Near misses |
||
(1, |
([1,1,0,1,0,0,1,1,1,0,0,0],[7]) |
||
(1, |
([1,1,0,1,0,0,1,0,1,1,0,0],[9]) |
||
(1, |
([1,1,0,1,0,0,1,0,1,0,0,1],[11]) |
||
(1, |
([1,0,1,1,0,1,1,0,1,0,0,0],[8]) |
||
(1, |
([1,0,1,1,0,0,0,1,1,0,0,0],[6]) |
||
(1, |
([1,0,0,1,0,1,0,1,1,0,0,0],[5]) |
||
(1, |
([1,0,0,1,0,0,0,1,0,1,1,1],[11]) |
||
(1, |
([1,0,0,1,0,0,0,0,0,0,0,0],[7]) |
||
(1, |
([1,0,0,0,1,1,0,0,1,0,1,0],[7]) |
||
([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> |
</pre> |
||