假設用GNU的大整數library,所有int變量都可以是任意大的自然數。其中用print的那一行有可能造成0除以0,在C裏麵整數0除以0程序要crash的。請問這個程序會crash嗎?如果你知道會不會,你就知道了哥猜想對不對。
存在類似的程序,它不需要任何外界輸入,運行過程是決定地而且唯一的,但是連數學家都不可能知道它會不會crash。有意思吧?
int is_prime(int x) {
for (int i = 2; i*i
if (mod(x, i) == 0) { // i divides x, not a prime
return 0;
}
}
return 1;
}
void test_goldbach() {
for (int n = 6; ; n = n + 2) { // Iterate over even numbers n.
for (int x = 2; x
if (!is_prime(x)) {
continue;
}
for (int y = 2; y
if (!is_prime(y)) {
continue;
}
// Now we have x and y prime numbers.
// If x + y == n, we test the next n.
if (x + y == n) {
goto next_n;
}
}
}
next_n:;
// By construction of the loops, if n invalides Goldbach,
// then x == y == n, and (n - x) / (n - y) will crash
// with a division by 0 error.
// Otherwise, the code can go on.
print((n - x) / (n - y));
}
}
給一個具體的軟件,你們看看會不會crash?
所有跟帖:
•
這問題不難證明,我想了一下就得出答案
-tsc12-
♂
(84 bytes)
()
02/28/2010 postreply
18:14:02
•
沒讀第一行嗎?
-UberAlles-
♂
(23 bytes)
()
02/28/2010 postreply
18:23:01
•
沒有一部電腦整數可以無限增加的,你連這都不懂
-tsc12-
♂
(0 bytes)
()
02/28/2010 postreply
18:45:34
•
你事先不知道任何電腦的升級上限,道理就這麽簡單。
-UberAlles-
♂
(214 bytes)
()
02/28/2010 postreply
19:59:26
•
哪有人寫個程序不知道在哪run啊?您是Java程序員吧?program once, debug everywhere
-先想一想再說-
♂
(0 bytes)
()
02/28/2010 postreply
20:19:08
•
我終於明白您的邏輯了,您覺得一個bug free的程序是放之四海而皆run的啊?
-先想一想再說-
♂
(34 bytes)
()
02/28/2010 postreply
20:22:17
•
本來就是計算理論的東西,當然要放之四海皆準。
-UberAlles-
♂
(56 bytes)
()
02/28/2010 postreply
20:37:25
•
軟件都有特定運行平台,脫離運行平台探討軟件無異於無本之木,無源之水
-先想一想再說-
♂
(0 bytes)
()
02/28/2010 postreply
20:39:39
•
我早就說過學數學的是在象牙塔裡看世界
-tsc12-
♂
(206 bytes)
()
02/28/2010 postreply
20:51:43
•
你沒有明白他的意思,太令人遺憾。可計算理論是計算機科學的基礎
-企鵝肥肥-
♂
(16 bytes)
()
03/03/2010 postreply
01:34:37
•
另外不管計算機如何升級,一個躺著的8比他所能處理的數大躺著的8那麽多倍
-先想一想再說-
♂
(0 bytes)
()
02/28/2010 postreply
20:31:32