Mercurial > hg > aoc
comparison 2017/day16.d @ 21:f1f0220b5f7c
day 16: simply loop
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Sat, 16 Dec 2017 23:47:26 -0500 |
parents | 8d1edc9efcb4 |
children |
comparison
equal
deleted
inserted
replaced
20:8d1edc9efcb4 | 21:f1f0220b5f7c |
---|---|
27 } | 27 } |
28 return cast(string) progs.idup; | 28 return cast(string) progs.idup; |
29 } | 29 } |
30 | 30 |
31 auto iteratePerm(string[] ops, string progs) { | 31 auto iteratePerm(string[] ops, string progs) { |
32 string[] seenprogs = [progs]; | 32 string[] seenprogs; |
33 string result = progs; | 33 for(string result = progs; |
34 while(true) { | 34 !seenprogs.canFind(result); |
35 result = ops.parseOps(result); | 35 result = ops.parseOps(result)) { |
36 if(seenprogs.canFind(result)) { | |
37 break; | |
38 } | |
39 seenprogs ~= result; | 36 seenprogs ~= result; |
40 } | 37 } |
41 return seenprogs[1_000_000_000 % seenprogs.length]; | 38 return seenprogs[1_000_000_000 % seenprogs.length]; |
42 } | 39 } |
43 | 40 |