There’s a point in the film where Caleb is entering code on Nathan’s workstation. And unlike code you’d find in other films, this one actually serves a useful purpose as mentioned in my earlier post.

If you’d like to play with the code in Google’s own Code Playground, you can copy & paste this snippet adapted to work with google’s webapp API:

import webapp2

def sieve(n):
    x = [1] * n
    x[1] = 0
    for i in range(2,n/2):
            j = 2 * i
            while j < n:
                    x[j]=0
                    j = j+i
    return x
  
def prime(n,x):
    i = 1
    j = 1
    while j <= n:
            if x[i] == 1:
                    j = j + 1
            i = i + 1
    return i - 1

def DeusEx():
  x=sieve(10000)
  code = [1206,301,384,5]
  key =[1,1,2,2,]
  
  out = "".join(chr(i) for i in [73,83,66,78,32,61,32])
  for i in range (0,4):
      out += str(prime(code[i],x)-key[i])
  return out

# WebApp 
class MainHandler(webapp2.RequestHandler):

  def get(self):  # pylint:disable-msg=invalid-name
    """Handle GET requests."""
    self.response.write(DeusEx())

APP = webapp2.WSGIApplication([
    ('/.*', MainHandler),
], debug=True)

In case you were wondering, the ISBN number is generated by concatenating the 1206th, 301th, 384th, and 5th prime number, where each pair is subtracted by an N starting with 1, 2, and so on:

The 1,206th prime is 9,781. -1
The 301st prime is 1,993. -1
The 384th prime is 2,657. -2
The 5th prime is 11. -2
= 9780 1992 2655 9

73,83,66,78,32,61,32 are the ascii characters for “ISBN = ”

Of course, the name of the function “sieve” is a reference to a method of reducing number of prime candidates as described on this wiki http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes

Advertisements