Added day 6.
This commit is contained in:
parent
fb08d89d85
commit
cf52f4996e
|
@ -1,7 +1,7 @@
|
||||||
import std.stdio;
|
import std.stdio;
|
||||||
|
|
||||||
import day5.part1;
|
import day6.part1;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
hydrothermalVents();
|
lanternFish();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
1,2,1,1,1,1,1,1,2,1,3,1,1,1,1,3,1,1,1,5,1,1,1,4,5,1,1,1,3,4,1,1,1,1,1,1,1,5,1,4,1,1,1,1,1,1,1,5,1,3,1,3,1,1,1,5,1,1,1,1,1,5,4,1,2,4,4,1,1,1,1,1,5,1,1,1,1,1,5,4,3,1,1,1,1,1,1,1,5,1,3,1,4,1,1,3,1,1,1,1,1,1,2,1,4,1,3,1,1,1,1,1,5,1,1,1,2,1,1,1,1,2,1,1,1,1,4,1,3,1,1,1,1,1,1,1,1,5,1,1,4,1,1,1,1,1,3,1,3,3,1,1,1,2,1,1,1,1,1,1,1,1,1,5,1,1,1,1,5,1,1,1,1,2,1,1,1,4,1,1,1,2,3,1,1,1,1,1,1,1,1,2,1,1,1,2,3,1,2,1,1,5,4,1,1,2,1,1,1,3,1,4,1,1,1,1,3,1,2,5,1,1,1,5,1,1,1,1,1,4,1,1,4,1,1,1,2,2,2,2,4,3,1,1,3,1,1,1,1,1,1,2,2,1,1,4,2,1,4,1,1,1,1,1,5,1,1,4,2,1,1,2,5,4,2,1,1,1,1,4,2,3,5,2,1,5,1,3,1,1,5,1,1,4,5,1,1,1,1,4
|
|
@ -0,0 +1,28 @@
|
||||||
|
module day6.part1;
|
||||||
|
|
||||||
|
import std.file;
|
||||||
|
import std.stdio;
|
||||||
|
import std.math;
|
||||||
|
import std.string;
|
||||||
|
import std.algorithm;
|
||||||
|
import std.conv;
|
||||||
|
import std.array;
|
||||||
|
import std.parallelism;
|
||||||
|
|
||||||
|
ulong computeGrowth(ulong initial, ulong t) {
|
||||||
|
return (t <= initial) ? 1 : computeGrowth(6, t - initial - 1) + computeGrowth(8, t - initial - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void lanternFish() {
|
||||||
|
auto f = File("source/day6/input.txt", "r");
|
||||||
|
ulong t = 256;
|
||||||
|
ulong[] fish = f.readln().strip().split(",").map!(s => s.to!ulong).array;
|
||||||
|
ulong total = 0;
|
||||||
|
// WARNING!!! Only use this on a PC with >= 24 threads.
|
||||||
|
writefln("Using %d threads.", taskPool.size());
|
||||||
|
foreach (idx, i; taskPool.parallel(fish, 1)) {
|
||||||
|
total += computeGrowth(i, t);
|
||||||
|
writefln("Computed growth for fish %d", idx);
|
||||||
|
}
|
||||||
|
writefln("%d", total);
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
3,4,3,1,2
|
Loading…
Reference in New Issue