Twelve statements: Difference between revisions

Content deleted Content added
Simpler D entry
Simpler D entry
Line 180:
=={{header|D}}==
{{trans|Python}}
<lang d>import std.stdio, std.typecons, std.algorithm, std.range,std.functional;
std.array, std.functional;
 
immutable texts = [
Line 212 ⟶ 211:
s => sumi(s[6 .. 9]) == 1,
s => sumi(s[0 .. 11]) == 4];
 
void show(in bool[] st, in bool[] matches, in bool isPartial) {
if (isPartial) {
immutable pos = matches.countUntil(false);
writefln(`Missed by statement %d: "%s"`, pos + 1, texts[pos]);
} else
writeln("Solution:");
write(" ");
foreach (i, t; st)
writef("%d:%s ", i + 1, t ? "T" : "F");
writeln();
}
 
void main() {
Line 245 ⟶ 232:
 
foreach (sols, isPartial; zip([full, partial], [false, true]))
foreach (stm; sols) {
show(stm.tupleof,if (isPartial); {
immutable pos = matchesstm[1].countUntil(false);
writefln(`Missed by statement %d: "%s"`, pos + 1, texts[pos]);
pos + 1, texts[pos]);
} else
writeln("Solution:");
write(" ");
foreach (i, t; ststm[0])
writef("%d:%s ", i + 1, t ? "T" : "F");
writeln();
}
}</lang>
{{out}}