This file contains hidden or 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 collections import defaultdict | |
import heapq | |
ENGLISH = defaultdict(list) | |
for w in open("/usr/share/dict/american-english"): | |
w_stripped = w.strip() | |
ENGLISH[tuple(sorted(w_stripped))].append(w_stripped) | |
print heapq.nlargest(1, ENGLISH.itervalues(), key=len)[0] |
This file contains hidden or 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 collections import defaultdict | |
import heapq | |
ENGLISH = defaultdict(list) | |
for w in open("/usr/share/dict/american-english"): | |
w_stripped = w.strip() | |
ENGLISH[tuple(sorted(w_stripped))].append(w_stripped) | |
print heapq.nlargest(1, ENGLISH.itervalues(), key=len)[0] |
This file contains hidden or 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
import numpy as np | |
import cProfile | |
def bits_to_int(bits,): | |
n = 0 | |
for b in bits[::-1]: | |
n *= 2 | |
n += b | |
return n |
This file contains hidden or 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 iter_splits(l): | |
if not l: | |
yield ONE, ONE | |
else: | |
head, tail = l[0], l[1:] | |
for (left, right) in iter_splits(tail): | |
yield left + [head], right | |
yield left, right + [head] |
This file contains hidden or 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 iter_splits(l): | |
if not l: | |
yield [], [] | |
else: | |
head, tail = l[0], l[1:] | |
for (left, right) in iter_splits(tail): | |
yield left + [head], right | |
yield left, right + [head] |
This file contains hidden or 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 bits_to_int(bits,): | |
n = 0 | |
for b in bits[::-1]: | |
n *= 2 | |
n += b | |
return n | |
def zeros_matrix(N): | |
return [[0] * N for i in range(N)] |
This file contains hidden or 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
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int size; | |
cin >> size; | |
// <- input |
This file contains hidden or 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
Let's assume we found a solution with N not a power of 2. | |
The problem is N does not divide the number of configuration of the board... | |
Let's show that. | |
Since your pal is supposed to enter the room and point out the magic case, the solution | |
implies a mapping from the configuration of the board to one of the cases. | |
Let's call this mapping f and gives number to the cases. Call | |
E = [0..N] and P=the set of configurations. | |
Its cardinal is 2^N |
This file contains hidden or 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
import random | |
N = 100 | |
def permutation(S=100000): | |
l = range(N) | |
for i in xrange(S): | |
random.shuffle(l) | |
yield l |
This file contains hidden or 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/env python | |
def quick_quantiles(data, ranks): | |
# well there are better heuristics | |
# than that but that's not the point of | |
# this. | |
pivot = (pivot_val, pivot_count) = data[0] | |
if len(data) == 1: | |
return [pivot_val] | |
left = [it for it in data if it < pivot] |