Twelve statements: Difference between revisions
Content deleted Content added
Updated D entry |
|||
Line 262: | Line 262: | ||
"exactly 4 of the preceding statements are true"]; |
"exactly 4 of the preceding statements are true"]; |
||
alias curry!(reduce!q{a + b}, 0) |
alias sumi = curry!(reduce!q{a + b}, 0); |
||
immutable bool function(in bool[])[] funcs = [ |
immutable bool function(in bool[])[] funcs = [ |
||
s => s.length == 12, |
s => s.length == 12, |
||
s => sumi(s[$-6 .. $]) == 3, |
s => sumi(s[$ - 6 .. $]) == 3, |
||
s => sumi(s[1 .. $].stride(2)) == 2, |
s => sumi(s[1 .. $].stride(2)) == 2, |
||
s => s[4] ? (s[5] && s[6]) : true, |
s => s[4] ? (s[5] && s[6]) : true, |
||
Line 280: | Line 280: | ||
void main() { |
void main() { |
||
enum nStats = 12; |
enum nStats = 12; |
||
Tuple!(const |
Tuple!(const(bool)[], const(bool)[])[] full, partial; |
||
foreach (n; 0 .. 2 ^^ nStats) { |
foreach (immutable n; 0 .. 2 ^^ nStats) { |
||
const st = iota |
const st = nStats.iota.map!(i => !!(n & (2 ^^ i))).array; |
||
auto truths = funcs.map!(f => f(st) |
auto truths = funcs.map!(f => f(st)); |
||
const matches = zip(st, truths) |
const matches = zip(st, truths) |
||
.map!(s_t => s_t[0] == s_t[1] |
.map!(s_t => s_t[0] == s_t[1]) |
||
.array |
.array; |
||
immutable mCount = matches.sumi |
immutable mCount = matches.sumi; |
||
if (mCount == nStats) |
if (mCount == nStats) |
||
full ~= tuple(st, matches); |
full ~= tuple(st, matches); |
||
Line 296: | Line 296: | ||
foreach (sols, isPartial; zip([full, partial], [false, true])) |
foreach (sols, isPartial; zip([full, partial], [false, true])) |
||
foreach (stm; sols) { |
foreach (const stm; sols) { |
||
if (isPartial) { |
if (isPartial) { |
||
immutable pos = stm[1].countUntil(false); |
immutable pos = stm[1].countUntil(false); |
||
Line 306: | Line 306: | ||
foreach (i, t; stm[0]) |
foreach (i, t; stm[0]) |
||
writef("%d:%s ", i + 1, t ? "T" : "F"); |
writef("%d:%s ", i + 1, t ? "T" : "F"); |
||
writeln |
writeln; |
||
} |
} |
||
}</lang> |
}</lang> |