Mercurial > hg > aoc
comparison 2017/day23.d @ 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 |
comparison
equal
deleted
inserted
replaced
29:f2c11215006d | 30:c64fab7ed515 |
---|---|
3 import std.string: split; | 3 import std.string: split; |
4 import std.conv: to, ConvException; | 4 import std.conv: to, ConvException; |
5 | 5 |
6 import std.math: sqrt; | 6 import std.math: sqrt; |
7 import std.range: iota, stride; | 7 import std.range: iota, stride; |
8 import std.algorithm: filter; | 8 import std.algorithm: filter, any; |
9 | 9 |
10 auto isComposite(long p) { | 10 auto isComposite(long p) { |
11 foreach(x; 2..sqrt(cast(double) p)) { | 11 return iota(2, sqrt(cast(double) p)).filter!(x => p % x == 0).any; |
12 if (p % x == 0) { | |
13 return true; | |
14 } | |
15 } | |
16 return false; | |
17 } | 12 } |
18 | 13 |
19 auto runProgram(string[] opcodes, bool shortcircuit=false) { | 14 auto runProgram(string[] opcodes, bool shortcircuit=false) { |
20 | 15 |
21 long ip = 0; | 16 long ip = 0; |