51 lines
766 B
D
51 lines
766 B
D
import std.algorithm;
|
|
import std.uni;
|
|
import std.array;
|
|
import std.file;
|
|
import std.stdio;
|
|
import std.range;
|
|
import std.conv;
|
|
import std.string;
|
|
|
|
void main()
|
|
{
|
|
readText("input").calculateTotalNumberOfQuestions.writeln;
|
|
}
|
|
|
|
auto setIntersectionRoR(RoR)(RoR ror)
|
|
{
|
|
assert(!ror.empty);
|
|
return ror.map!(to!(dchar[]))
|
|
.reduce!((r1, r2) => r1.setIntersection(r2).array);
|
|
}
|
|
|
|
auto calculateTotalNumberOfQuestions(string input)
|
|
{
|
|
return input.splitter("\n\n").array.map!((group) {
|
|
return group.splitter.map!(person => person.representation.dup.sort.array.assumeUTF)
|
|
.setIntersectionRoR.count;
|
|
}).sum;
|
|
}
|
|
|
|
unittest
|
|
{
|
|
auto input = `abc
|
|
|
|
a
|
|
b
|
|
c
|
|
|
|
ab
|
|
ac
|
|
|
|
a
|
|
a
|
|
a
|
|
a
|
|
|
|
b
|
|
|
|
yx`;
|
|
|
|
assert(input.calculateTotalNumberOfQuestions == 8);
|
|
}
|