digitalmars.D.learn - ctfe - out of memory
- simendsjo (21/21) Jun 05 2011 It's fun to solve the euler problems at compile time, but I'm often
- bearophile (4/6) Jun 05 2011 Don wants to improve the CT interpreter, so maybe your problem will even...
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); }
Jun 05 2011
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
Jun 05 2011