這段49字符的C程序可運行10^10100890年

y37f 9年前發布 | 4K 次閱讀 C程序

這段 49 字符的C程序可運行 10^10100890 年,是不是很有趣?來看看吧

a[1<<20];n;main (){while(!(n>>20))n=++a[n]?0:n+1;}

/* Quite slow program in 49 characters Andrew Belt

Assuming an int is 32 bits, this program halts in around 2^(32*2^20) loops. This will take at least 10^10100890 years.

The array a is essentially a large integer spread across consecutive ints. This program simply increments the integer and halts when it overflows. I believe this approach gives the most loops possible with a state variable of 4*2^20 bytes (4 MiB).

Future improvements might include allocating memory on the heap instead, or opening and closing emacs in each iteration of the loop. */</pre>

 本文由用戶 y37f 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!