|
|
|
|
|
by sibrahim
2207 days ago
|
|
There's no need to store all previous states to detect a cycle: it can be done using just twice the original memory. You can model the state transitions as a linked list and use Floyd's classical tortoise and hare algorithm to (eventually) determine a cycle exists. Initialize "tortoise" and "hare" as two copies of initial state and advance hare by two instructions and tortoise by one each iteration. A cycle is reported if the two states become equal again. |
|