~This Will contain spoilers~
~If you haven't seen the movie, this will not make ANY sense~
~The movie is almost like "Hunger Games" and "Inception" combined, I highly recommend watching it~
You may think that the ending of the movie did not make any sense at all or maybe confused you by a bit. The ending showed all the students leaving their books one by one to Zimit's table and the last person (which is Petra) ended up staying in the classroom to speak with Zimit. As their conversation flows, the audience will pick up hints that they are secretly having an affair. And here is how the ending explains the reason why Zimit purposely gave James and Petra their role. Zimit thinks that James is no good for Petra because he is not intelligent enough for her. But Petra told Zimit that she is in love therefore choosing to be with James because "being smart isn't everything."
During the entire film, Zimit is enforcing to his students' brains that logical decisions will save the human race and they agreed, they accepted their roles and understood the hierarchy of which occupations are more important and which are not. But when James started questioning why Zimit gave him and Petra specific roles, Zimit did not gave him an answer so James demanded another iteration. Petra agreed to do another one, James see through Zimit but could not figure out why he is picking on him when Zimit gave him a role as a farmer that is gay. Logically speaking, he does not or would not feel comfortable enough to be with a woman meaning he cannot help the reproduction of human race resulting for him to be "useless."
Petra stole the gun from Zimit's satchel and began being in charge of their own story. Throughout the movie the students were using pure logic in order for them to choose the right people for the remaining slots in the bunker to rebuild a new society after the apocalypse. But Petra had it all figured out from the beginning. Since her and Zimit has or had something going on, she told him that it's never going to happen. But Zimit is pushing her buttons by punishing James' role in the gene pool to make it look like he's never going to be a good partner for Petra. This is the reason why Petra agreed to do another iteration, to change things up and to teach their philosophy teacher a real lesson that he deserve.
Petra used emotions over logic when she started choosing who should get to fill in the spots. For example; the fashion designer, because nice clothing will boost confidence plus being creative means it will help for future productivity. Another is the harpist that has autism together with the opera singer to produce harmonious music. She chose people that did not get a chance to fill in slots from previous iteration including the poet. Zimit is starting to get mad and decided to deduct points from Petra's grade because she is ignoring everything that he taught her through the entire movie. Petra figured out that the group has been depressed so she chose the people that will help them emotionally.
After spending time in the bunker, they finally got out and Zimit showed up saying that they are going to die easily because they don't have the necessary skills that they need. But Petra explained to him that they might die soon, but because they had fun and lived their life right, they are not going to run away from death anymore.
It all made sense that Zimit is making Petra choose logical decisions instead of using emotion,.. which is ironic because he's doing all these iteration because he is emotionally attached to her.
Now let's talk about the final scenes with Zimit. The three random scenes are basically showing the possible endings for him. They all started with him walking up the stairs, first he was eating a sandwich and live normally the rest of his life, second, he pulls a gun out and shot himself, and lastly, he sits there and had a vision of Petra being happy which means he learned something from her in that final class. Death can wipe out and entire race, but when you consider your life with different possibilities, you won't need another life because ONCE is enough.
There is a big difference between surviving and living your life.