given n, print all the combinations of 0...(n-1) of length n
n = 2
00
01
10
11
def iterate_by_chunk(word, chunk_length): | |
i = 0 | |
while i < len(word): | |
yield word[i:i+chunk_length] | |
i += chunk_length | |
def check(word, pattern, len_pattern_word, i_offset): | |
"""check if the word match the pattern""" | |
pattern_length = len(pattern)*len_pattern_word |
#https://code.google.com/codejam/contest/7214486/dashboard | |
from collections import deque | |
from itertools import combinations | |
class Matrix: | |
@staticmethod | |
def from_string(M): | |
return Matrix([list(x.strip()) for x in M.split('\n')]) | |
def __init__(self,M): |
from pprint import pprint as pp | |
from collections import deque | |
def find_bridge_bf(nodes, edges, a, b): | |
""" | |
Simple brute-force bridge finding | |
For each edge, explore nodes from *a* and try to reach b without using the edge | |
If it can't reach the *b*, it was a bridge | |
""" | |
for edge in edges: |
#!/usr/bin/env python3 | |
import sys | |
""" | |
Use a naive implementation of a Trie: http://en.wikipedia.org/wiki/Trie | |
""" | |
class Trie: | |
def __init__(self): | |
self.children = {} #letter<->sub-Trie mappings |
#Execute a type 3 grammar | |
rules2 = """ | |
S -> ATC | |
A -> aA | | |
C -> cC | | |
T -> abT | ab | |
""" | |
class bcolors: |
import numpy as np | |
import sys | |
import random | |
MAX_ERASE_RATIO = 30 # 10 => 27 500 | |
DILLATE_SIZE = 0 | |
ERASED = -8 | |
EXTRA = -6 |
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 | |
0 1 1 0 1 1 0 0 1 1 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1 1 1 0 0 1 1 1 0 1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 | |
0 1 0 1 1 -1 1 0 -1 1 0 1 1 0 1 0 1 0 1 1 0 -1 1 0 1 -1 1 0 1 -1 1 1 1 -1 0 1 0 1 1 0 0 0 1 -1 0 -1 0 -1 1 0 0 -1 1 | |
1 1 1 1 0 1 -1 1 1 1 0 1 -1 0 1 0 1 1 -1 0 1 1 -1 -1 1 0 -1 1 0 0 1 0 1 1 0 1 1 1 -1 -1 1 1 1 1 1 1 1 0 1 1 1 1 1 | |
1 1 0 1 1 -1 0 1 0 1 0 1 -1 1 -1 1 0 1 1 1 1 1 0 0 -1 0 -1 1 1 1 -1 0 1 1 1 0 -1 1 1 0 1 0 1 1 1 1 1 1 0 0 -1 -1 1 | |
-1 1 -1 -1 -1 1 1 -1 0 1 0 -1 1 1 -1 1 0 1 -1 1 0 -1 0 1 -1 0 0 -1 1 0 -1 0 -1 1 1 -1 0 -1 -1 0 0 -1 1 0 0 -1 -1 -1 -1 -1 0 1 1 | |
0 1 0 0 1 0 0 1 1 -1 1 1 1 0 1 1 0 -1 0 1 1 1 1 1 0 0 1 1 1 1 0 1 -1 1 1 1 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 0 0 -1 | |
-1 0 -1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 -1 1 1 -1 0 1 1 0 0 1 1 1 1 -1 -1 0 1 1 0 1 1 1 1 0 1 1 | |
0 -1 0 -1 1 1 0 0 0 1 1 1 1 -1 1 1 1 1 1 1 1 1 1 0 -1 1 1 1 1 1 0 1 1 1 -1 1 1 0 1 1 1 0 1 1 1 1 1 0 -1 1 0 1 0 | |
1 1 |
from __future__ import print_function | |
from itertools import * | |
def find_switches(a,b): | |
return {i for i,v in enumerate(a) if v != b[i]} | |
def transform(a,switchs): | |
r = "" | |
for i, v in enumerate(a): | |
if i in switchs: |