ctfe - out of memory
    simendsjo 
    simen.endsjo at pandavre.com
       
    Sun Jun  5 02:21:09 PDT 2011
    
    
  
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);
}
    
    
More information about the Digitalmars-d-learn
mailing list