Mercurial > hg > aoc
changeset 15:817954f71d53
day 13: cache a calculation for speed
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 14 Dec 2017 10:36:38 -0500 |
parents | 56b75b62d591 |
children | 990a4fa2aebe |
files | 2017/day13.d |
diffstat | 1 files changed, 5 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/2017/day13.d +++ b/2017/day13.d @@ -5,7 +5,7 @@ import std.array: array; auto getHits(T)(T firewall, int init = 0) { - return firewall.filter!(xy => (init + xy[0]) % (2*(xy[1]-1)) == 0); + return firewall.filter!(xy => (init + xy[0]) % xy[2] == 0); } auto computeSeverity(T)(T firewall) { @@ -22,7 +22,10 @@ void main(string[] args) { auto firewall = File(args[1]).byLineCopy.map!( - x => x.split(": ").map!(to!int) + function(string x){ + auto v = x.split(": ").map!(to!int); + return v.array ~ (2*v[1] - 2); + } ).array; writeln(firewall.computeSeverity); writeln(firewall.findPassing);