Nolan’s Creed is in theaters right now, and many people are walking out of theaters wondering what the hell it’s all about.
I do not know if you understand, anyway, xiaobian is to see the clouds in the fog. Combining maxwell’s demon, the second law of thermodynamics and other physical knowledge, as well as various paradoxes of time, this sci-fi film gives the audience a new setting, which is different from all previous sci-fi films about time and space.
Today we’re not going to do a story analysis, but an algorithmic analysis of Creed. Not only that, but Nolan’s other big books can also be linked to algorithms. After reading this article, you might wonder: Nolan is not a programmer!
TENET Backtracking algorithm
The core science fiction premise of the creed is to reverse time by decreasing entropy.
This is similar to the backtracking algorithm: there are forward operations and reverse operations, in depth-first search, we modify the parameters, after recursive calls, have to change back.
1 path.add(node) 2 recursion(path, visited) // 4 Path. remove(node) // Backtracking 5 visited. Remove (node) // BacktrackingCopy the code
And the climax of the final time clamp battle is also the most confusing place for the audience, decent villains, red team blue team, forward and reverse a set of “combination” directly stun the audience!
The same is sometimes true of algorithmic interviews: even though there are thousands of ways to answer a question, we can’t figure it out. Can sigh 1: be my foundation not solid enough!
Don’t try to understand it. Feel it.
INCEPTION Recursion
Inception, one of Nolan’s most famous sci-fi films, shocked audiences when it was first released — how could sci-fi be so imaginative? Of course, Dicaprio’s performance takes the movie to a whole new level.
The layered dream setup in Inception is very similar to the recursive algorithm.
Suppose we want to go to level I, we have to go to level I-1. The same is true for recursion. To get to level I recursion, you have to do level I-1 recursion.
The dream extractor dies at one level and returns to the next, not the original dream.
Similarly, a return in a recursive algorithm destroys all local variables of the current level of recursion and returns to the previous level of recursion instead of the original entry.
1 void recursion(int deep) { 2 if (deep == 0) { 3 return; 4 } 5 recursion(deep + 1); // Recurse to the next level instead of the first; // return means to destroy 7}Copy the code
The death or change of the dreamer at one level does not affect the state of the dream at the next level. For example, the plums in the multiple layers of inception dreams are all called plums, but after sleeping in one layer, the plums in the next layer are completely irrelevant to the one above.
** After the variable I at the next level of recursion is modified, the variable I at the previous level is not affected. ** Even though the variables have the same name, they are actually different variables in different locations in memory.
From this point of view, Nolan’s logic has a more reliable and rigorous explanation, and it is no wonder that his science fiction film has attracted a lot of people, and everyone is eager to explore the “truth” of the movie.
Dunkirk-divide and Conquer
A soldier manages to get on a rescue ship for the evacuation of Dunkirk, a fighter jet engages in a fierce encounter with the Germans, and a civilian boat does nothing to back up Dunkirk, and finally everyone meets up on the beach of Dunkirk to complete the timeline.
This is Dunkirk, nordmann’s rare historical war film. Isn’t this ** * process [the narrative] separately and then merge the results together ** much like the divide-and-conquer approach we often encounter?
(One of Dunkirk’s most iconic “No words speak” shots)
Divide and rule means “divide and rule”. Usually we divide a complex problem into two or more identical or similar subproblems until the subproblems can be solved simply and directly. The solution of the original problem is the combination of the solutions of the subproblems. It is one of the classic optimization algorithms.
1 void divide(int left, int right) { 2 if(left == right) { 3 return; 4 } 5 //divide into parts 6 int mid = (left + right) / 2; 7 divide(left, mid); 8 divide(mid + 1, right); 9 // conquer left to right 10 return; 11}Copy the code
With this explanation, it seems that xiaobian can not watch the movie “normal” — most of the time thinking about what algorithm logic is used here, how to use programming to explain there. The movie of the god of nuo, the original is to cheat me to brush two!
Do you have any interesting comments on Noshen’s film, please leave us a comment in the comments section