June 05, 2011 ctfe - out of memory | ||||
---|---|---|---|---|
| ||||
It's fun to solve the euler problems at compile time, but I'm often running out of memory. Is there a way around this? import std.stdio; int numWithLongestChain(int max) { int maxIt = 0; int n; foreach(i; 1..max) { int it = 0; for(int c=i; c != 1; ++it) c = (c&1) == 0 ? c / 2 : c*3 + 1; if(it > maxIt) { maxIt = it; n = i; } } return n; } enum longest = numWithLongestChain(1_000_000); void main() { writefln("%d has the longest chain", longest); } |
June 05, 2011 Re: ctfe - out of memory | ||||
---|---|---|---|---|
| ||||
Posted in reply to simendsjo | simendsjo:
> It's fun to solve the euler problems at compile time, but I'm often running out of memory. Is there a way around this?
Don wants to improve the CT interpreter, so maybe your problem will eventually be solved.
Bye,
bearophile
|
Copyright © 1999-2021 by the D Language Foundation