Skip to content

Instantly share code, notes, and snippets.

View fulmicoton's full-sized avatar
🤪

Paul Masurel fulmicoton

🤪
View GitHub Profile
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]
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]
import numpy as np
import cProfile
def bits_to_int(bits,):
n = 0
for b in bits[::-1]:
n *= 2
n += b
return n
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]
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]
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)]
#include <iostream>
using namespace std;
int main()
{
int size;
cin >> size;
// <- input
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
import random
N = 100
def permutation(S=100000):
l = range(N)
for i in xrange(S):
random.shuffle(l)
yield l
#!/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]