The attached solver for the "escape from zurg" riddle doesn't compile with versions 2.007 and 2.008 anymore. Instead (from within emacs compilation mode) I get "compilation exited abnormally with code 5". Modifying the function writecrossing as follows void writecrossing(const Entry *e) { foreach(v;toys) if(e.cross&v.mask) writef("%s(%d), ",v.name, v.time); auto h = e.goal?"escape":"return"; writefln("%s; %d minutes left", h, e.timeleft); } solves the problem. Here the version of the program that doesn't compile. I've tried without success to produce a substantially shorter program that shows the same error. It seems to depend on the circumstances. import std.stdio; struct Toy { ulong mask; invariant(char)[] name; int time; }; Toy[4] toys = [{1,"Buzz",5},{2,"Woody",10},{4,"Rex",20},{8,"Hamm",25}]; struct Entry { int timeleft; bool goal; // true means that here is the goal of the escape ulong cross, // masks of characters that have just crossed here, there; }; ulong alltoys = (1<<toys.length)-1; void writecrossing(const Entry *e) { foreach(v;toys) if(e.cross&v.mask) writef("%s(%d), ",v.name, v.time); writefln("%s; %d minutes left", e.goal?"escape":"return", e.timeleft); } Entry[64] stack; Entry* p=&stack[0],q=&stack[1]; int solcnt = 0, timeoutcnt = 0, crosscnt = 0; void cross() { ++crosscnt; q.goal = !p.goal; q.here = p.there | q.cross; q.there = p.here & ~q.cross; if(q.goal && q.here==alltoys) { writefln("\nSolution %d",++solcnt); foreach(e;stack[2..q+1-&stack[0]]) writecrossing(&e); } else { p = q; q++; foreach(k,v;toys) { if(p.here&v.mask) { q.cross = v.mask; q.timeleft = p.timeleft - v.time; if(q.timeleft<0) timeoutcnt++; else if(q.cross!=p.cross) cross(); foreach(w;toys[k+1..length]) { if(p.here&w.mask) { q.cross = v.mask|w.mask; if(w.time>v.time) q.timeleft = p.timeleft - w.time; if(q.timeleft<0) timeoutcnt++; else if(q.cross!=p.cross) cross(); } } } } q = p; p--; } } int main () { q.timeleft = 60; p.there = alltoys; p.here = 0; p.goal = true; q.cross = 0; cross(); writef("\ncross() called %d times; timeout reached %d times", crosscnt, timeoutcnt); return 0; }
Fixed dmd 1.026 and 2.010
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル