Pergunta

So I was reading in a book of a certain paradox: Say you are in a room with a door opposite of you. In order to leave though, you must travel half the distance there each time. So the first stride you make half the distance, and the second stride you take half again, and so on (1/2 + 1/4 + 1/8) etc. The claim is if you will never reach the door if you continue like this. This is I guess easy to prove using calculus, but it would be interesting to simulate this in Java or any other program with a ball that starts on the left side, and makes its way to the right side by traveling half the distance each time, while showing the number of 'steps' taken so far and its progress. I would love to do it myself but I'm still a beginner in Java and dont know GUI programming. Can anyone simulate this?

(Sorry if this is not a 'real' question. I'm just really curious how many steps it would take for the ball to even look like it was almost there.)

Foi útil?

Solução

See this plot, which visualizes the paradox:

http://www.wolframalpha.com/input/?i=1-1/(2^n)+for+0<n<10

Outras dicas

you will run into numbers limits far before you run into the other door. abstracted it is:

var Distance=100;
var Traveled=0;
var Remaining=Distance/2

while(Traveled < Distance){
  echo Remaining
  Traveled=Traveled+Remaining
  Remaining=Remaining/2

}

running this on one of my boxes using PHP resulted in..
50
25
12.5
6.25
3.125
1.5625
0.78125
0.390625
0.1953125
0.09765625
0.048828125
0.0244140625
0.01220703125
0.006103515625
0.0030517578125
0.00152587890625
0.000762939453125
0.0003814697265625
0.00019073486328125
9.5367431640625E-5
4.7683715820312E-5
2.3841857910156E-5
1.1920928955078E-5
5.9604644775391E-6
2.9802322387695E-6
1.4901161193848E-6
7.4505805969238E-7
3.7252902984619E-7
1.862645149231E-7
9.3132257461548E-8
4.6566128730774E-8
2.3283064365387E-8
1.1641532182693E-8
5.8207660913467E-9
2.9103830456734E-9
1.4551915228367E-9
7.2759576141834E-10
3.6379788070917E-10
1.8189894035459E-10
9.0949470177293E-11
4.5474735088646E-11
2.2737367544323E-11
1.1368683772162E-11
5.6843418860808E-12
2.8421709430404E-12
1.4210854715202E-12
7.105427357601E-13
3.5527136788005E-13
1.7763568394003E-13
8.8817841970013E-14
4.4408920985006E-14
2.2204460492503E-14
1.1102230246252E-14
5.5511151231258E-15

a bit of numerical analysis in java. have a look at this

This is one of Zeno's Paradoxes It depends on what your definition of "almost" is. From a far enough vantage point, it can look like it is almost there no matter what the actual distance is.

As for a program to do this, your question is far too broad - it could be implemented in a number of ways. The key element is to update the distance of the ball to the wall to be one half of what it was in the previous "frame" or iteration.

If you want to do it in C++ here's the code:

float Distance;

cout << " Enter distance value :" << endl;
cin >> Distance;

while (Distance > 0){
    cout << Distance << endl;
(Distance = Distance /2);
}


return 0;

}

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top