Python Challenge – level 7 solution

It took me 2 days. I have no idea what the forum hint2: (i * 7, 43) means. It was misleading and wasted lots of my time thinking about it. The solution, at least mine, has nothing to do with it.

import string
from PIL import Image
im = Image.open("oxygen.png")
m = im.getdata()
i = 0
y = m[0][0]
s = ""
for x in m:
    if (x[0] == x[1] == x[2]) and (y == x[0]): #a grey pixel and same as last pixel
        i+=1
    else:
        # if i > 0: print i
# for some reason, "print s" showing nothing
# therefore using string.printable to solve it
        if chr(y) in (string.printable):
            s+=chr(y)*((i+2)/6)  # make every dot 6 pixels wide
                                 # and show first only 4 pixels wide 's' dot 
        i = 0
        y = x[0]
print s
>>> execfile('pc7-1.py')
smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]smart guy, you made it. the next level is [105, 110, 116, 101, 103, 114, 105, 116, 121]

Then copy the part to the second script to get the final answer:

import string
s = ""
t = 105, 110, 116, 101, 103, 114, 105, 116, 121

for i in range(len(t)):
    if chr(t[i]) in string.printable:
        s+=chr(t[i])
print s
>>> execfile('pc7-2.py')
integrity

Advertisements

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