Decision tables: Difference between revisions

Updated first D entry
m (→‎{{header|REXX}}: added support for superfluous blanks in answer. -- ~~~~)
(Updated first D entry)
Line 196:
<lang d>import std.stdio, std.algorithm, std.exception, std.array;
 
immutable struct DecisionTable {
alias immutable(bool)[] IBA;
const string[] conds, actions;
Line 204:
in size_t newLen)
pure nothrow {
bool[]auto result = new bool[newLen];
result[0 .. b.length] = b[];
return assumeUnique(result).assumeUnique;
}
 
this(inimmutable string[] c, in string[] a, in bool[][][] q)
immutable string[] a,
const immutable bool[][][] q) pure nothrow {
conds = c;
actions = a;
Line 217 ⟶ 218:
r[growTo(p[0], conds.length)] =
growTo(p[1], actions.length);
rules = assumeUnique(r).assumeUnique;
}
 
Line 226 ⟶ 227:
auto iTested = growTo(tested, conds.length);
if (iTested in rules)
foreach (immutable i, immutable(byte) e; rules[iTested])
if (e) rightActions ~= actions[i];
rightActions ~= actions[i];
 
if (!rightActions.empty)
Line 241 ⟶ 243:
string answer = "no";
try
answer = stdin.readln();
catch (StdioException)
writeln("no");
Line 253 ⟶ 255:
void main() {
enum { F = false, T = true }
immutable d = immutable(DecisionTable)(
["Printer is unrecognised",
"A red light is flashing",
Line 274 ⟶ 276:
);
 
d.consult();
}</lang>
{{out}}