aoc2020/day6/part2/main.d

52 lines
766 B
D
Raw Permalink Normal View History

2020-12-08 09:13:05 +01:00
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);
}