Twelve statements: Difference between revisions

Content deleted Content added
→‎{{header|Haskell}}: using unicode operators. Might not be a terribly smart thing to do, those who know haskell, feel free to change it
Line 25: Line 25:
tf (x:xs) = map (True:) s ++ map (False:) s where s = tf xs
tf (x:xs) = map (True:) s ++ map (False:) s where s = tf xs


sumbool = sum . map fromEnum
sumbool = length . filter id
wrongness b = sumbool . zipWith (/=) b . map (\f -> f b)
wrongness b = sumbool . zipWith (/=) b . map (\f -> f b)


statements = [ (==12) . length,
statements = [ (==12) . length,
sumto 3 [len - 6..],
3 [length statements-6..],
sumto 2 [1,3..],
2 [1,3..],
\b -> not (b!!4) || all (b!!) [5,6],
4 [4..6],
\b -> not $ any (b!!) [2..4],
0 [2..4],
sumto 4 [0,2..],
4 [0,2..],
sumto 1 [1,2],
1 [1,2],
\b -> not (b!!6) || all (b!!) [4,5],
6 [4..6],
sumto 3 [0..5],
3 [0..5],
sumto 2 [10,11],
2 [10,11],
sumto 1 [6,7,8],
1 [6,7,8],
sumto 4 [0..10]
4 [0..10]
] where
] where
(⊂) s x = \b -> s == (sumbool . map (b!!) . takeWhile (< length b)) x
len = length statements
sumto s x b = s == (sumbool . map (b!!) . takeWhile (< length b)) x
(→) a x = \b -> not (b!!a) || all (b!!) x


main = let t n s = filter ((==n).fst) [(wrongness b s, b) | b <- tf s] in do
main = let t n s = filter ((==n).fst) [(wrongness b s, b) | b <- tf s] in do
Line 64: Line 64:
(1,[False,False,False,True,False,False,False,True,False,True,True,True])
(1,[False,False,False,True,False,False,False,True,False,True,True,True])
</pre>
</pre>

=={{header|Perl 6}}==
=={{header|Perl 6}}==
<lang perl6>sub infix:<→> ($protasis,$apodosis) { !$protasis or $apodosis }
<lang perl6>sub infix:<→> ($protasis,$apodosis) { !$protasis or $apodosis }