Home > Python, PythonChallenge.Com > PythonChallenge – Level 1

PythonChallenge – Level 1


Homepagehttp://www.pythonchallenge.com/pc/def/map.html

How I solve:

– According to the picture, I can see that this might relate to character transformation; it is a conversion letter map,

K->M

O->P

E->G

– So first try is to convert the input data following this map

from string import maketrans

data = "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."

table_from = "koe"
table_to = "mpg"

print data.translate(maketrans(table_from, table_to))

– Well the result is un-readable. So I try to expand it to whole alphabet table, because it maps each letter by the next two letter on the alphabet. Make another try:

from string import maketrans

data = "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."

table_from = "abcdefghijklmnopqrstuvwxyz"
table_to = "cdefghijklmnopqrstuvwxyzab"

print data.translate(maketrans(table_from, table_to))

– Now the result is very human-readable.

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.

– Oh, so apply for the url, I reach the next level 🙂

Cheers,
Pete Houston

  1. No comments yet.
  1. No trackbacks yet.

Leave a comment