# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1513633367 18000 # Node ID 4e7e7835f1dbcbb7a4589a61ec7309168d35ae10 # Parent f1f0220b5f7ccef9529a3a75a83fd06520fd1409 day 17 diff --git a/2017/day17.d b/2017/day17.d new file mode 100644 --- /dev/null +++ b/2017/day17.d @@ -0,0 +1,31 @@ +import std.stdio; +import std.algorithm: find; +import std.conv: to; + +auto getBuffer(ulong skip) { + ulong[] circ = [0]; + ulong pos = 0; + foreach(y; 1..2018) { + pos = (pos + skip) % circ.length + 1; + circ = circ[0..pos] ~ y ~ circ[pos..$]; + } + return circ; +} + +auto getPastZero(ulong skip) { + ulong pos = 0; + ulong pastzero = 0; + foreach(length; 1..50_000_000) { + pos = (pos + skip) % length + 1; + if (pos == 1) { + pastzero = length; + } + } + return pastzero; +} + +void main(string[] args) { + auto circ = getBuffer(args[1].to!ulong); + writeln(find(circ, 2017)[1]); + writeln(getPastZero(args[1].to!ulong)); +}