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
v | |
0 The blank line above this one matters; | |
2 it's the "storage space" where we keep | |
1 our user input and accumulator. | |
p v < >v | |
>>1+:11g`!| " | |
>&11p1>:11g\%| 1 D | |
vg12:< - e | |
>+21p ^ 2 f |
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
from itertools import takewhile, cycle | |
MAX_MATCH_LENGTH = 18 | |
MAX_LOOKBEHIND = 1 << 12 | |
def length_of_match(data, x, y, limit): | |
"""The number of matching consecutive characters starting at `x` and `y` in `data`.""" | |
return len(list(takewhile( | |
lambda x: x[0] == x[1], | |
zip(data[x:x+limit], data[y:y+limit]) | |
))) |
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
from itertools import takewhile, cycle | |
MAX_MATCH_LENGTH = 18 | |
MAX_LOOKBEHIND = 1 << 12 | |
def length_of_match(data, x, y, limit): | |
"""The number of matching consecutive characters starting at `x` and `y` in `data`.""" | |
return len(list(takewhile( | |
lambda x: x[0] == x[1], | |
zip(data[x:x+limit], data[y:y+limit]) | |
))) |
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
from itertools import takewhile, cycle | |
MAX_MATCH_LENGTH = 18 | |
MAX_LOOKBEHIND = 1 << 12 | |
def length_of_match(data, x, y, limit): | |
"""The number of matching consecutive characters starting at `x` and `y` in `data`.""" | |
return len(list(takewhile( | |
lambda x: x[0] == x[1], | |
zip(data[x:x+limit], data[y:y+limit]) | |
))) |
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
from itertools import takewhile, cycle | |
MAX_MATCH_LENGTH = 18 | |
MAX_LOOKBEHIND = 1 << 12 | |
def length_of_match(data, x, y, limit): | |
"""The number of matching consecutive characters starting at `x` and `y` in `data`.""" | |
return len(list(takewhile( | |
lambda x: x[0] == x[1], | |
zip(data[x:x+limit], data[y:y+limit]) | |
))) |
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
def a(b): | |
m=map;c=''.join;s=str;y=s.isalpha;n=next;f=filter;u=m(s.isupper,f(y,b));d=f(y,c(m(c,m(sorted,s.lower(b).split()))));o='' | |
return reduce(lambda o,c:(lambda x:x,s.upper)[n(u)](n(d))if y(c)else c,b,'') | |
print(a(input())) |
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
#!/usr/bin/python | |
def mangle(sentence): | |
uppercase = map(str.isupper, sentence) | |
mangled = filter(str.isalpha, | |
''.join(map(''.join, map(sorted, sentence.lower().split()))) | |
) | |
out = '' | |
for c in sentence: | |
caps = next(uppercase) |
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
#!/usr/bin/python | |
import telnetlib | |
HOST = "python.sctf.io" | |
PORT = 25565 | |
tn = telnetlib.Telnet(HOST, PORT) | |
tn.read_until(b'!', timeout=1) |
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
#!/usr/bin/python | |
func_dict = { | |
'+' : lambda x,y:y+x, | |
'-' : lambda x,y:y-x, | |
'*' : lambda x,y:y*x, | |
'/' : lambda x,y:y/x | |
} | |
# Given the RPN string, return a function that calculates the nth term | |
# based on the list of previous terms. |
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
#!/usr/bin/python | |
c=lambda f,o:lambda a:eval('%s%s'%(f(a),o)) | |
a=lambda b,s,n:[s]+a(b,b(s),n-1)if n>0 else[s] | |
d=str.split(input());b=lambda x:x | |
for o in d[:-2]:b=c(b,o); | |
print(*a(b,*map(int,d[-2:]))) |