Created
December 4, 2015 06:30
-
-
Save mthipparthi/7dab48b4ac71610cce86 to your computer and use it in GitHub Desktop.
Pycthon challenges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chal 1 : | |
chal 2 : | |
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.' | |
a=[ord(x)+2 if x.isalpha() else ord(x) for x in s] | |
s="".join([chr(x) for x in a]) | |
s.replace('{','a').replace('|','b') | |
>>> s="http://www.pythonchallenge.com/pc/def/map.html" | |
>>> a=[(ord(x)+2-ord('a'))%26+ord('a') if x.isalpha() else ord(x) for x in s] | |
>>> x="".join([chr(x) for x in a]) | |
>>> x | |
'jvvr://yyy.ravjqpejcnngpig.eqo/re/fgh/ocr.jvon' | |
http://wiki.pythonchallenge.com/index.php?title=Level1:Main_Page | |
http://www.pythonchallenge.com/pc/def/ocr.html | |
chal3: | |
view-source:http://www.pythonchallenge.com/pc/def/ocr.html | |
rare=[] | |
file = open('abc.txt') | |
for line in file: | |
for a in list(line): | |
if (ord(a) > 65 and ord(a) <= 90) or (ord(a) >= 97 and ord(a) <= 122): | |
rare.append(a) | |
result = ''.join(rare) | |
ans | |
http://www.pythonchallenge.com/pc/def/equality.html | |
chal4: | |
def check_left(pos, array): | |
if len([ if ord(x) >= 65 and ord(x) <= 90 for x in array[pos-3:pos]]) == 3 && len([ if ord(x) >= 65 and ord(x) <= 90 for x in array[pos:pos+3]]) == 3: | |
def check_right(): | |
result = [] | |
def process_array(array): | |
for pos,val in enumerate(pos, array): | |
if pos >= 3 and pos < len(array)-3: | |
if len([ if ord(x) >= 65 and ord(x) <= 90 for x in array[pos-3:pos]]) == 3 && len([ if ord(x) >= 65 and ord(x) <= 90 for x in array[pos:pos+3]]) == 3: | |
result.append(val) | |
file = open('ip.txt') | |
for line in file: | |
process_array(list(line)) | |
print result | |
[A-Z]{3}[a-z][A-Z]{3} | |
import re | |
pattern = re.compile('[^A-Z][A-Z]{3}[a-z][A-Z]{3}[^A-Z]') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment