changeset 30:c64fab7ed515

day 23: moar functional (lol)
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Tue, 02 Jan 2018 16:39:49 -0500
parents f2c11215006d
children 6761b3bbaa70
files 2017/day23.d
diffstat 1 files changed, 2 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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) {