Skip to content

Instantly share code, notes, and snippets.

@cammckinnon
cammckinnon / gist:2390097
Created April 15, 2012 04:42
message word sorting
cipher_words.sort(key = lambda x: -len(x))
@cammckinnon
cammckinnon / gist:2390127
Created April 15, 2012 04:49
substitution cipher decryption
# python 2.7.3
# reads ciphertext from ./in.txt and a whitespace-delimited
# dictionary of english words from ./dictionary/wordlist.txt
import string
from collections import defaultdict
from itertools import izip
# english dictionary
words = set()
@cammckinnon
cammckinnon / gist:2400465
Created April 16, 2012 18:16
reverse graph
from collections import defaultdict
def reverseGraph(Graph):
newGraph = defaultdict(lambda: [0])
for left in Graph:
leftsNeighbors = Graph[left][1:]
for right in leftsNeighbors:
newGraph[right].append(left)
return newGraph
@cammckinnon
cammckinnon / gist:2400946
Created April 16, 2012 19:30
olivia's code - fixed
from collections import defaultdict
def Dictionary(Filename):
dic = {}
dicR = {}
i = 0
with open(Filename) as f:
for line in f:
l, r = line.split()
l, r = int(l), int(r)
# python 2.7.3
# reads ciphertext from ./in.txt and a whitespace-delimited
# dictionary of english words from ./dictionary/wordlist.txt
import string
import sys
from collections import defaultdict
from copy import copy
from itertools import izip
/*
* Classic example grammar, which recognizes simple arithmetic expressions like
* "2*(3+4)". The parser generated from this grammar then computes their value.
*/
start
= additive
additive
= left:multiplicative "+" right:additive { return {op: '+', toks: [left, right]}; }
(
(
lambda
(()())
params
(
fib
(() ((())))
)
call fib[6]
(((()())((()((()))))((()((())))((()()(()))((())()()()()())((())()()()))(()((())))))((()())((()()())(()()()(())))((()()()())((()()(())())(()()())((())()))(()()())((()(()))((()()()(()))((()(()()))(()()())((())())))((()()()(()))((()(()()))(()()())((())()())))))))
((()()())(()(()()))((()(()))((())()()()()()()())((()()(()))((())()()()()()()()()())
((())()()()()()()()()()()))))((()()())(()(()()()))((()(())(())())((())()()()()()()(
)()()()()()()()()()()()()()()()()()()()()()()()()())))((()(()))((()(())(())())((()(
()))(()(()()))((())()()()()()()())))((()(())(())())((()(()))(()(()()))((())()()()()
)))((()(())(())())((()(()))(()(()()))((())()()()()()()()()()()())))((()(())(())())(
(()(()))(()(()()))((())()()()()()()()()()()())))((()(())(())())((()(()))(()(()()))(
(())()()()()()()()()()()()()()())))(()(()()()))((()(())(())())((()(()))(()(()()))((
())()()()()()()()()()()()()()()()()()()()()()())))((()(())(())())((()(()))(()(()())
)((())()()()()()()()()()()()()()())))((()(())(())())((()(()))(()(()()))((())()()()(
)()()()()()()()()()()()()())))((()(())(())())((()(()))(()(()()))((())()()()()()()()
#include <stdio.h>
/*
compiles with 'gcc -Wall' with no errors or warnings.
*/
int main() {
// vars
int a[10];
int i = 0;
long long L = 0;