# HG changeset patch # User Jordi GutiƩrrez Hermoso # Date 1514929189 18000 # Node ID c64fab7ed515ffbd9404407682c5be10b2b1873e # Parent f2c11215006dcdf47aa62742afe03ad85657fd6f day 23: moar functional (lol) diff --git a/2017/day23.d b/2017/day23.d --- a/2017/day23.d +++ b/2017/day23.d @@ -5,15 +5,10 @@ import std.math: sqrt; import std.range: iota, stride; -import std.algorithm: filter; +import std.algorithm: filter, any; auto isComposite(long p) { - foreach(x; 2..sqrt(cast(double) p)) { - if (p % x == 0) { - return true; - } - } - return false; + return iota(2, sqrt(cast(double) p)).filter!(x => p % x == 0).any; } auto runProgram(string[] opcodes, bool shortcircuit=false) {