Hacker News new | comments | show | ask | jobs | submit login
Inception movie explained programmatically with C and assembly (github.com)
165 points by geospeck 117 days ago | hide | past | web | favorite | 87 comments



This reminds me of an awesome site my friend Ben Howdle built called moviesascode. Users would contribute tiny code snippets that summarised a whole movie. As an example:

.titanic{ float:none; }

Unfortunately he lost the site when he switched hosts, I've been badgering him for years to restart it.



Thanks for the link. Some of those are really great.

Here's the original titanic/float one: https://web.archive.org/web/20120315194303/http://moviesasco...



Hmm, I agree with Rick on this one:

    Rick: Boy, you're really gonna flip your lid over this one.
    Morty: Oh, w-wh... what is it?
    Rick: It's a device, Morty, that when you put it in your ear, you can enter people's dreams, Morty. It's just like that movie you keep crowing about!
    Morty: You're talking about Inception?
    Rick: That's right, Morty! This is gonna be a lot like that, except y'know, it's gonna me-beh... make sense.
    Morty: Inception made sense!
    Rick: You don't have to try and impress me, Morty! 
and

    Rick: "It's been six hours. Dreams move one one-hundredth the speed of reality, and dog time is one-seventh human time. So, you know, every day here is like a minute. It's like Inception, Morty, so if it's confusing and stupid, then so is everyone's favorite movie."
I still bugs me that they float in one layer because the fall in another (or the other way around) then one layer deeper this is not a problem at all. It seems so arbitrary. Like they based in on a novel but ignored all the parts where they actually put in an effort to help you suspend your disbelieve.


While we're here, can someone explain how a "dream within a dream" works in Inception ? Presumably someone has to "fall asleep" inside their (or someone else's) dream and go into a dream state again on another level so to speak. The only way I can see the brain implementing that is to dream of its own state so completely that it can run itself as a virtual machine, and fall asleep inside that VM. I haven't read the code, but I doubt the C implementation includes a VM that can run inside itself, Smalltalk-style.


> While we're here, can someone explain how a "dream within a dream" works in Inception ?

Exactly like that. It happens in real-life and no doubt that's where they based it from. It happened to me a couple of times already, the deepest I got was 4 levels.

Real-life sleeping > level 1: sleeping > Level 2: sleeping > Level 3: sleeping > level 4: awake

Usually, it was very bad. A form of nightmare. You slowly get aware of it, even to the point that your brain tells you that you are awake. Then when something happens that you want to wake up (for example, you died, or you suddenly got aware you're sleeping), you will indeed wake up, up to the next level.

Once again, your brain will tell you that you are finally awake.

The first experience I had of this was when I was barely a teenager. It was a nightmare within a nightmare within a nightmare within a nightmare. When I got fully aware I was sleeping, that's when I fought, waking up, then waking up, then waking up, then finally waking up to the real world.

Problem was, I was no longer sure if it was the real world I woke up to. To this day, I sometimes think I am still sleeping.

Just like the other ending in Inception. Hence I love that movie. I can relate.


> To this day, I sometimes think I am still sleeping.

This is a well-known problem in the lucid dreaming community. There are some surprisingly easy ways to check. I find the simplest is to count my fingers out loud. If there are definitely five on each hand, then I'm awake. If there's any problem coming up with a count, then I'm asleep, no matter how much it seems like I'm awake.


Unless that's just a feature of the deeper dream levels, not this one...

(I also have dreams where I wake up over and over and over, only to realize that shit, I'm still dreaming. It's surprisingly disconcerting, there's a kind of physical sense of losing my mind involved.)


Honestly you could just lack the awareness to notice. That's not a slight against you, acute awareness in the dream state is not an innate ability and must be practiced frequently in order to be successful with it.

In any dream state, you can test the rules of the world around you and see that your brain doesn't quite build the world to completeness. Light switches will not work, text will morph and shift either in front of your eyes or when you look away and turn back, the people around you will spontaneously morph into others, you can breathe through your nose when it's plugged, etc.

What happened to you is referred to as a false awakening. Testing the reality of your situation by checking clocks, breathing through your nose, counting your fingers, etc. will all quickly put you into a more lucid and aware state. From there you either continue or, more commonly, you wake up.


> Testing the reality of your situation by checking clocks, breathing through your nose, counting your fingers, etc. will all quickly put you into a more lucid and aware state.

I haven't thought of that. What became my anchor for the past few years have been my schedule or being aware of it.

But there were rare cases when in my dream state, the reality is happening in the dream and that totally puts me off greatly. A good example is when I'm dreaming I woke up, went to work, and got home.

When I woke up, I didn't know until I arrived at the office and learned no day has passed yet.


Ooh, interesting. I learned to lucid dream in my late teens or early 20s and I've enjoyed it most of the time (except those times when I'm losing control).

It's true, if you're too much into lucid dreaming, there are times when you can't tell if you've woken up. Parts of the dream spill overs in the waking world.


Does pulling your hands in opposite directions work for you?

It worked for me once and I got really excited. Too excited and woke up :(. Never happened again (not that I've been trying).


one time i tried this and each of my fingertips turned into little hands with the same dexterity of my hands. needless to say i believe i was asleep.


Once after I spent the whole day writing a parser in Haskell I had a dream in which I was falling asleep under a tree, but such that first my torso fell asleep, then my arms/legs, then my head, fingers, toes, etc. Cracked me up.


I used to get those as well as a kid. The technique, nightmare-within-nightmare was a trope of 80s horror movies and that's where we got it (incepted?) I believe :)

On the movie, I think the really interesting part was not the recursive dreaming but rather how our ideas- that we think are novel - are not actually ours. After watching it, me and my wife started observing it on each other. Me or she would come up with something and the other would point out some conversation in the recent past that seeded it. Fun and a bit scary.


True. In the creative writing world, there is this notion that we are all pulling the ideas from our stories in some alternate space where ideas freely flow.

And when we notice how our original idea (and we're sure it's the first) is too similar to another who beat us to publication, yet both parties are sure no one copied anyone... well, it gives credence to the idea that there is an alternate space out there... or maybe we can access each other's ideas on some quantum level.

Speaking of quantum level, it might even be possible altogether.


I had that happen once. In this dream, I was in a 'fake' world that had some kind of trick or flaw to it. When I found the trick, that world disappeared and I found myself in another world with a different trick. This went on all night, I think there were at least four of these worlds before I actually woke up. It messed with my head for a while.


There is a theory which states that if ever anyone discovers exactly what the Universe is for and why it is here, it will instantly disappear and be replaced by something even more bizarre and inexplicable.

There is another theory which states that this has already happened.

— Douglas Adams, The Restaurant at the End of the Universe


Ooh, interesting, very interesting! (And scary)


Another movie with the same theme is Waking Life. I also found it a lot more thought-provoking than Inception.

http://www.imdb.com/title/tt0243017/


Thanks, I'll watch it!


That sounds horrifying.


Yep. And the nightmare, of all things, is Dracula and vampires. I'm aware of Dracula, but vampires, didn't even know that term then (early to mid 90s).


when the first dream "forks" and the new dream narrative starts, are you aware that this new dream is "inside" the host dream ?


Nope. Usually when I first become aware of the dream world, I am already levels deep. The only time I became aware of those levels is when I start to wake up and I ended up still being in a dream totally different from the level I woke up from.

I've been trying to figure out how to know I am levels deep but to no avail.


It is like falling asleep in a Docker container. You don't know what is outside of the container and you don't know where you are because kubernetes doesn't tell you. Everything is abstracted.

This is pretty neat overview though: http://www.inception-explained.com/


Inception as a set of commands to start and stop docker containers within docker containers, and programs within those containers. As a bonus, the last command should be trying to determine if the top level is a docker container, and segfault.


Time moves faster in a dream than it does in the real world.

Code running in a container runs slower than in the outside world ;-)


It's a plot device that is left unexplained.

Nolan tends to write really, really, really soft scifi.


His trick is to have characters who sound SUPER sure of what they're doing. Winking at the camera, looking determined, talking total bullshit but it doesn't matter. You want to believe it makes sense because it all feels so cool!


For me it was even more distressing that this is somehow a thing you can do, but you can only go 3 levels then something completely different happens. Why 3? Why not 15? For something like this to be the case, it would require the brain physically designed to perform these functions.


Yep it's dreaming within a dream exactly. I've had it happen to three levels deep (assuming this world is real). Woke up then woke up again, then woke up a third time and now I'm in this world.


User-mode Linux was capable of self-hosting. There's always that.


UML inside UML doesn't work for me:

  $ linux
  Locating the bottom of the address space ... do_syscall_stub : ret = -1, offset = 1052680, data = 18ca9008
  do_syscall_stub: syscall 192 failed, return value = 0xffffffff, expected return value = 0x1000
      syscall parameters: 0x1000 0x1000 0x7 0x11 0x3 0x2449
  Failed to flush page for address 0x1000
  Killed


I was fairly certain I had done it before. I did some Googling to sanity-check myself and found, "UML can be compiled to run within UML" [1]. I don't seem to recall any unusual compiling options to make it work, but then that was a long time ago, as was that document, I suspect (although it has no dates). Maybe it's broken...

[1] http://user-mode-linux.sourceforge.net/old/UserModeLinux-HOW...


I briefly glanced at the code and was expecting a game like clock to emulate the time dilation that the dream within a dream caused.

I can't remember in the movie what was the deepest dream possible but you could pick a large base ticker value in case whatever you decide as the lowest dream is not (I remember the movie leaving that as an open question).


Great. Now do Memento.


Or Primer.


timestamp = now

while (true); if ( now - timestamp > rand() ) now = now - rand();


$ man tac


    def memento(x=Float::INFINITY)
      memento(x-1)
    end


The events in color are reverse-order and take place after the shooting of Jimmy. The events in black-and-white are in-order and take place before the shooting.

The movie interleaves them so you have a post-shooting event then a pre-shooting event until you get to the end where the shooting happens then it leads to the exposition.


That sounds similar to the structure of the Culture novel "Use of Weapons":

https://en.wikipedia.org/wiki/Use_of_Weapons


I was going for just the overview


Now, if only it were actually readable...


Which parts are unreadable. Looks like pretty mundane code to me.


What would your suggestions be to make this readable?


Less of it.


Hmm, something's broken on x64 OS X (10.11), in the last line:

> [Fischer] exiting back to reality from level [1] with the THOUGHT:

> Illegal instruction: 4


To fix this, I changed L14 of the Make file from

  ARCH_FLAGS := -m64
to

  ARCH_FLAGS := -m32


Our CS1010 teacher in college used to test us on movies. I believe one year he had done inception. Other years he did transformers, Star Wars etc.


What is the point? Is it indented as Art? Was it made simply for the fun of coding?


It's a toy project. Looks like a fun way to brush up on pthreads and play with self-modifying code. The fun part about reading it (for me, at least) is the novel idea of using the plot of Inception as the "spec" for the program's behavior. :)


what's the point of your comment ? is it intended as art ? was it made simply for the fun of commenting ?


The point of my question was/is to learn about opinions/thoughts from other people who has a perspective that is different from my own.


Uncaught RangeError: Maximum call stack size exceeded


It was probably a weekend project that was over three full weekends.


Why not lisp


I can only assume C was used on purpose in tribute to how complex and complicated the original movie was.


Not trying to be snarky, but what's complex about Inception? Once you're past the two premises (you can infiltrate dreams; you can dream recursively) this is just a heist movie without any significant plot twist, by which I mean there is no world-changing or premise-questioning event, and only one apect of said premises (the altered length of "lived time") is explored.

To use other Nolan movies as a point of comparison, Memento and The Prestige are much more accomplished in terms of fully exploiting their concepts. And within the domain of movies exploring the theme of "your lived experience is a dream/illusion", there are much more effective and/or complex examples[1].

I have a feeling that Inception is kind of like Interstellar in terms of public perception: people are psyched by the initial concept, so they don't pay attention to the fact that its underlying narrative structure is pretty run-of-the-mill.

I guess I sound like a buzzkill! If I've missed any deep concept within Inception, I'd be glad to be schooled/enlightened, since I like understanding what makes a movie tick. Also, I don't think it's a bad movie at all, just that it's not that complicated once we're past the initial disorientation.

[1] Before anybody asks, in no particular orders: In The Mouth Of Madness, Mulholland Drive, Paprika, Written By. In a different vein: Eternal Sunshine of the Spotless Mind. Hell, even Total Recall (1990 version) and The Matrix probably apply.


> Not trying to be snarky, but what's complex about Inception?

Having to constantly track how many levels deep you are, how time flows at that level, the rules for what may/may not wake you out of a level, the specific actions going on during the specific levels at those rates of time, how they interact all together, and whether you were right about the level the movie took place at the entire time and what that means for it all, and the information you've learned and leaned on to make the assumptions you have at every point.

It's a very complex, complicated movie built out of very simple premises.

> I have a feeling that Inception is kind of like Interstellar in terms of public perception

Possibly. I wasn't super impressed by Interstellar, but not for the same reasons people around me always seemed to point out. To me it felt like a story that might have wanted to make some interesting philosophical points but decided to hide them almost completely behind staid and rote characters and plot and overly interpersonal emotion driven motivations, given the scope of the project they were supposed to be involved in.

> If I've missed any deep concept within Inception

I don't think so, I think you just misinterpreted what I meant by complicated. It's not conceptually or philosophically complicated, it's mechanically complicated. In the same way that two separate expressions of an algorithm or procedure may be simple or complicated, elegant or a bunch of spaghetti code. Inception is a simple set of concepts expressed as spaghetti code, but done so purposefully with the intent to entertain.


> Having to constantly track how many levels deep you are, how time flows at that level, the rules for what may/may not wake you out of a level, the specific actions going on during the specific levels at those rates of time, how they interact all together, and whether you were right about the level the movie took place at the entire time and what that means for it all, and the information you've learned and leaned on to make the assumptions you have at every point.

The cool thing about the movie is that you can misunderstand nearly all of that, and when the music begins playing across all three (four?) dreams you immediately grasp the consequence for the plot.

It's like not caring about Gnu make's console diarrhea flashing past the screen, until the final message tells you a test failed and suddenly going, "Oh, shit."


I totally agree. I'm a big sci-fi movie fan, and not usually a snob, but I found both Inception and Interstellar to be pretty mundane.

FWIW, a classic sci-fi movie that leaves me similarly cold is Bladerunner (although I love Philip K. Dick).


If you're really curious what Inception is doing, you may enjoy this essay:

http://filmreadings.com/2015/12/31/a-skeleton-key-to-incepti...

Shortest explanation? The film combines Christian symbolism (Matthew 7:24), the Platonic theory of the soul (anamnesis), the Fisher King story from the Grail Legends, and the Greek legend of Theseus in the Labyrinth. The four parables intertwine effortlessly: Mal is simultaneously the Minotaur in the labyrinth, the Platonic negative (who falls into the world and forgets the truth she once knew), and the faithless temptress who chooses to build on sand.

The film then does to the audience what it shows the heist team doing to Fischer ("your mind is the scene of the crime"). So it is a meta-heist film that discusses how art communicates with its audience, all the while following the convention of the heist genre in showing us exactly what it is doing and then surprising us when it pulls it off.


Thanks, that's the kind of things I had not considered. It looks interesting, but I'll have to read it more thoroughly, as based on a first skimming I'm not entirely convinced by some of the views. For example, Fischer is not rekindled with his father; he is, if anything, cheated of this most sacred bond, and the way the author explains away that it is not so (because it would invalidate their theory) is not convincing. Likewise it is very odd that they present as a victory of sort the ending, where Cobb chooses the possible lie of being reunited with his kids based on his "faith", and ignores the evidence that his totem could provide him (and I understand that at a meta level he has previously rejected the "false faith" that was Mal, and his kids are supposed to stand in for "real faith", but the story is still the story and any meta analysis has to be consistent with it -- and here the story might in fact be telling us he is still choosing "believing" over "knowing"). If they're correct this vision of Fischer and of the ending, to me, would mean that the message of the movie is "choose faith: choose the lies you want to believe in!" which, somehow, I don't think is what the screenwriter had in mind.

I guess I'll have to re-watch that movie, then.


You're not a buzzkill. You're pointing out the obvious. Nolan 's execution is technically and visually superb, but there is little depth. These ideas were plumbed to their very depths in Science Fiction by the end of the 1970s.

Stanislaw Lem's Futurological Congress explores similar ideas with both brilliance and humour (avoid the dire movie based on the novel however).


+1 for Mulholland Drive. I used to love these movies that attempted to be mind-bending, and seeing that film made me realize that I mostly loved their wish-fulfillment/power fantasy elements.

I think Mulholland Drive was such an effective foil for power fantasies because it started in a dream state then revealed the depressing and pedestrian triggers for that state. I saw it late in graduate school and the sense of failure permeating Naomi Watts' character in the second half hit very close to home. I don't know if it would have worked if the frame for the movie had not been so mundane (in contrast to something like Inception, which relies so heavily on a black box dream-infiltration device).


I feel the same way. I was expecting some really deep movie that raised questions and made me think - that's how Inception seemed to be billed. Instead, I found it rather shallow and uninspiring. Glad to find I'm not literally the only one.


I think it's complex like polyrhytmic drumming is complex. Sure, they're just hitting drums to keep a beat as a basic concept.

In this sense Inception and Dunkirk are very similar. There's a wonderful choreography to make all these variable-speed timelines hang together in viewer-time.


What movie would be convoluted enough to warrant C++?


Cloud Atlas?


Primer?


Primer is extremely hard to follow as shot (on purpose) but it's actually fairly reasonable once it's all laid out on paper. I think an "implementation" wouldn't be too hard.

https://en.wikipedia.org/wiki/Primer_(film)#/media/File:Time...


I've seen a different graph of the Primer timeline, which is somewhat more involved.

http://unrealitymag.com/wp-content/uploads/2011/09/primer-ch...


Downstream color

cout << ARGB.value << endl


This is cute, but Downstream Color is such a disturbing movie that it deserves more than just an interpretation of its title in code. Something that simulates the life cycle of the spore-thingy in code would be pretty cool.


*Upstream color


(2011)


Awesome.


so novel and simple!


Why is C in quotes?

Better question: Why isn't assembly in quotes?


Not sure, we've removed the quotation marks. (Apologies to Chesteron.)


I guess I'll have to resign myself to not knowing why some people program in "C" as opposed to C or JAVA as opposed to Java.

Some people always write their surname in ALL-CAPS, too, and I never understood that, either.

But it isn't so much that I don't understand. I don't understand a lot of things. It's that nobody else seems to understand, either. Even the ones who do it. Or they've all taken a vow to keep this information from the rest of us.


> Some people always write their surname in ALL-CAPS, too, and I never understood that, either.

Because different cultures order the components of their names differently, and writing the surname in all-caps indicates which is which.


Easy there, pal. I think people write "C" because the letter C alone looks odd in a plain English sentence.


That doesn't fully explain what I've observed, and your condescension is not appreciated.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: