Skip to content

Instantly share code, notes, and snippets.

View CT075's full-sized avatar

Cameron Wong CT075

View GitHub Profile
@CT075
CT075 / dailyprog243.bfg
Created December 2, 2015 03:27
Find abundant or deficient numbers
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
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])
)))
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])
)))
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])
)))
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])
)))
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()))
#!/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)
@CT075
CT075 / rpg_auto.py
Created April 28, 2015 04:23
Solution for "Deceptive Ports" in sCTF
#!/usr/bin/python
import telnetlib
HOST = "python.sctf.io"
PORT = 25565
tn = telnetlib.Telnet(HOST, PORT)
tn.read_until(b'!', timeout=1)
@CT075
CT075 / recurrence_hard.py
Last active August 29, 2015 14:17
Daily Programmer #206 naive implementation
#!/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.
@CT075
CT075 / recurrence_obfu.py
Created March 17, 2015 03:48
Project Euler 206
#!/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:])))