Home > Python > Instagram Puzzle solution

Instagram Puzzle solution

Instagram challengeSo. I managed to solve Instagram’s puzzle and submit it hoping to get a job (or at least a T-shirt!). I understand there are quite a few people who’d be interested to see the solution so I decided to publish it here. It goes without saying that by now thousands of people have submitted their solutions so if you’re planning to send this in, well you’re an idiot. jk feel free if you want🙂

Before showing you the code let me tell you a cool story my bros🙂


00:00 am Tuesday Nov 13 : I’m browsing through tech blogs and see the challenge advertised on TechCrunch. Immediately start drawing possible solutions on paper. it seems to be really easy.

00:30 am: I decide to stay awake and write the code, shouldn’t be hard. The challenge tips to use of PIL, a python library. Python… it’s been 3 years since last time I barely spoke any python. I Try to get DrPython and PIL installed on OS X. no luck. then I download Ubuntu,  install it on my machine.

01:30 am: DrPython and PIL work fine on Ubuntu. Time to think of an algorithm, then draw a few flowcharts to get an idea of how to write the code.

02:00 am: It seems like I have a solid and logical solution, shouldn’t take much to write the code. start coding

03:00 am: dear lord, I can’t speak any python at all😦 help Google!

04:00 am: Migrane kicks in, terrible headache. but Google’s once again proven to be helpful!

05:00 am: I’m making progress managed to score the shreds based on their compatibility now need to find out how to find the right order (didn’t think of this when I did the flowchart:/ ) My head, it is in a BAD situation.

07:30 am: Phew! it works!! spent ages on figuring out how to crop the regions from the original and place them in the out put only to realise it was actually written on Instagram’s blog post as a “hint”😐 at this point I feel like someone’s axing my head… from inside.

08:00 am: solution submitted. now I can get some sleep… oh wait. need to be in uni at 10:/


Now, these few lines took me 8 hours to write. Surely if I knew python i wouldn’t have taken so long. It sounds dead simple. yeah it is to read, but certainly not to come up with! I hereby grant permission to anyone to use any part (or the entire) code for any (peaceful) reason. Credit is not demanded but much appreciated🙂 feel free to ask any questions.

NOTE: you need to download the shredded puzzle from here, name it in.png and put it in the same folder as your .py file

"""Instagram Challenge"""

from PIL import Image
import math
import operator 

def bigpick(matrix,i):
    for j in range(20):
        if newtemp>temp:
    return index
def make_list(size):
 mylist = []
 for i in range(size):
 return mylist
def make_matrix(rows, cols):

 matrix = []
 for i in range(rows):
 return matrix
def getpix(x, y):
       width, height = image.size
       pixel = data[y * width + x]
       return pixel

image = Image.open('in.png')
data= image.getdata()
x, y = 20, 90
scores= make_matrix(20,20)

width, height = image.size
for shred_number in range(20):
 x1, y1 = shred_width * shred_number, 0
 x2, y2 = x1 + shred_width, height
 points= x1,y1,x2,y2
for i in range(20):
    for j in range(20):
        for y in range(359):
            for p in range(3):
                if diff<10:
            if tempscore==3:

for i in range(20):

resault.sort(key=lambda x:x[0],reverse=True)


while orderIndex>0:
 for item in resault:
    if item[2]==order[orderIndex]:

unshredded=Image.new("RGBA", image.size)
for i in order:
    unshredded.paste(source_region, destination_point)
  1. URL
    December 12, 2011 at 7:56 am

    brilliantly insightful post. If only it was as easy to implement some of the solutions as it was to read and nod my head at each of your points 325422

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: