Python Challenge – level 1 solution (map)

My first solution:

s="g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj. "

t=""
for i in range(len(s)):
    if 97 <= ord(s[i]) <= 122:
        if ord(s[i]) < 121:
            t = t + chr(ord(s[i])+2)
        else:
            t = t + chr(ord(s[i])-26+2)
        # print t
    else:
        t=t+s[i]
print t
 >python pc1.py
i hope you didnt translate it by hand. thats what computers are for. doing it in by hand is inefficient and that's why this text is so long. using string.maketrans() is recommended. now apply on the url.

My new solution using the recommended method after seeing the words:

import string
s="g fmnc wms bgblr rpylqjyrc gr zw fylb. rfyrq ufyr amknsrcpq ypc dmp. bmgle gr gl zw fylb gq glcddgagclr ylb rfyr'q ufw rfgq rcvr gq qm jmle. sqgle qrpgle.kyicrpylq() gq pcamkkclbcb. lmu ynnjw ml rfc spj. "

sfrom = "abcdefghijklmnopqrstuvwxyz"
sto = "cdefghijklmnopqrstuvwxyzab"
table = string.maketrans(sfrom, sto)
print string.translate(s, table)

Apply the same way to the URL: map->ocr

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