day6: solve part 1 & 2
This commit is contained in:
parent
e99eae4c1f
commit
71f6069359
4 changed files with 4446 additions and 0 deletions
2179
day6/part1/input
Normal file
2179
day6/part1/input
Normal file
File diff suppressed because it is too large
Load diff
37
day6/part1/main.d
Normal file
37
day6/part1/main.d
Normal file
|
@ -0,0 +1,37 @@
|
|||
import std.algorithm;
|
||||
import std.uni;
|
||||
import std.array;
|
||||
import std.file;
|
||||
import std.stdio;
|
||||
|
||||
void main()
|
||||
{
|
||||
readText("input").calculateTotalNumberOfQuestions.writeln;
|
||||
}
|
||||
|
||||
auto calculateTotalNumberOfQuestions(string input)
|
||||
{
|
||||
return input.splitter("\n\n")
|
||||
.array.map!(group => group.filter!isAlpha.array.sort.uniq.count).sum;
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
auto input = `abc
|
||||
|
||||
a
|
||||
b
|
||||
c
|
||||
|
||||
ab
|
||||
ac
|
||||
|
||||
a
|
||||
a
|
||||
a
|
||||
a
|
||||
|
||||
b`;
|
||||
|
||||
assert(input.calculateTotalNumberOfQuestions == 11);
|
||||
}
|
2179
day6/part2/input
Normal file
2179
day6/part2/input
Normal file
File diff suppressed because it is too large
Load diff
51
day6/part2/main.d
Normal file
51
day6/part2/main.d
Normal file
|
@ -0,0 +1,51 @@
|
|||
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);
|
||||
}
|
Loading…
Reference in a new issue