Write the longest possible loop

Recently I was asked this question in a technical discussion. What is the longest cycle that can be written in computational science, given the machine / architecture on which it should run? This loop should be as long as possible, but not an infinite loop and should not end in a program crash (recursion, etc.)

I honestly did not know how to attack this problem, so I asked him if this was possible. He said, using some concepts of computer science, you can come up with a hypothetical number that may be impractical, but nonetheless it will not be infinite.

Anybody here; knows how to analyze / attack this problem.

PS Choosing the highest limit for a type that can hold the highest numerical value is apparently not the answer.

Thanks in advance,

+3
source share
5 answers

You get into the training field.

Simply put (let's stay in deterministic fields ...) your computer / machine may be in a finite number of states that are transmitted during the algorithm. each state is unique, and only once once, otherwise you would have to defnition have an infinite loop. like "goto". we can remove this restriction, but it does not make much sense, because then we can find a trivial algorithm that always has one more cycle than any other possible algorithm.

so it depends on the possible states of the machine that you could naively translate "with your plow."

: , X ? wikipedia

+10
+6

? , . , .

+1

, , (, Python Common Lisp), , , . , .

, . ( , ), , , 8 , - 2 ^ 8G. , .

, , , , , (, - ) .

. .

.

+1
source

If "long" means time, the following end loop should be a good bet:

for(unsigned long long i = 0; i < ULONG_LONG_MAX; ++i) sleep(UINT_MAX);

Well, this answer is not very serious, but in fact my opinion is that the question is completely useless to ask for an interview. What for? According to S. Lott's answer, this may be due to the Busy Beaver problem, which is almost 50 years old, and is completely unknown, because no one could use it in real work.

0
source

Source: https://habr.com/ru/post/1781913/


All Articles