#!/usr/bin/python import sys import Image # load image im = Image.open("sortme.jpeg") pix = im.load() # these are the sorted image fingerprints sorted = ["101101101101", "101111101001", "000111001001", "000001001010", "101101100100", "101001111111", "001001000000", "010010010010", "100100100100", "100111100110", "111010110110", "010010110110"] res = "" # loop through fingerprints to find 1st, 2nd, ... part for i in range(0,12): pos = 0 # image is 400x300, take every 100x100 part for y in range(0, 300, 100): for x in range(0, 400, 100): fingerprint = "" # create 4x3 array containing 4 pixel with 3 colors (RGB) check = pix[x+10,y+10] + pix[x+90,y+10] + pix[x+10,y+90] + pix[x+90,y+90] # loop though RGB-colors to create fingerprint # we need this because jpeg-converting seems to make colors differ for k in check: if k < 128: fingerprint = fingerprint + "0" if k >= 128: fingerprint = fingerprint + "1" # DEBUG OUTPUT: to create sorted-array manually # print(str(x) + ":" + str(y) + " --> " + fingerprint) # correct part found? if sorted[i] == fingerprint: res = res + str(pos) + ":" break pos += 1 # output in challenge format sys.stdout.write(res[0:len(res)-1])