Twelve statements: Difference between revisions
Content deleted Content added
new draft task |
|||
Line 21:
Extra credit: also print out a table of near misses, that is, solutions that are contradicted by only a single statement.
=={{header|Haskell}}==
<lang haskell>tf [x] = [[True], [False]]
tf (x:xs) = map (True:) s ++ map (False:) s where s = tf xs
sumbool = sum . map fromEnum
wrongness b = sumbool . zipWith (/=) b . map (\f -> f b)
statements = [ (==12) . length,
sumto 3 [len - 6..],
sumto 2 [1,3..],
\b -> not (b!!4) || all (b!!) [5,6],
\b -> not $ any (b!!) [2..4],
sumto 4 [0,2..],
sumto 1 [1,2],
\b -> not (b!!6) || all (b!!) [4,5],
sumto 3 [0..5],
sumto 2 [10,11],
sumto 1 [6,7,8],
sumto 4 [0..10]
] where
len = length statements
sumto s x b = s == (sumbool . map (b!!) . takeWhile (< length b)) x
main = let t n s = filter ((==n).fst) [(wrongness b s, b) | b <- tf s] in do
putStrLn "Answer"
mapM_ print $ t 0 statements
putStrLn "Near misses"
mapM_ print $ t 1 statements</lang>
{{out}}
<pre>
Answer
(0,[True,False,True,True,False,True,True,False,False,False,True,False])
Near misses
(1,[True,True,False,True,False,False,True,True,True,False,False,False])
(1,[True,True,False,True,False,False,True,False,True,True,False,False])
(1,[True,True,False,True,False,False,True,False,True,False,False,True])
(1,[True,False,True,True,False,True,True,False,True,False,False,False])
(1,[True,False,True,True,False,False,False,True,True,False,False,False])
(1,[True,False,False,True,False,True,False,True,True,False,False,False])
(1,[True,False,False,True,False,False,False,True,False,True,True,True])
(1,[True,False,False,True,False,False,False,False,False,False,False,False])
(1,[False,False,False,True,False,False,False,True,False,True,True,True])
</pre>
=={{header|Perl 6}}==
<lang perl6>sub infix:<→> ($protasis,$apodosis) { !$protasis or $apodosis }
|