chromehearts
BAN USERdef pprint(rows):
for r in rows:
print(" ".join([str(i) for i in r]))
def step(x, y, rows, cols, N):
#print('a', x,y, rows, cols)
if (x >= N) or (y >= N):
return False
for i in range(1, N+1):
if (i not in rows[x]) and (i not in cols[y]):
rows[x].append(i)
cols[y].append(i)
# print('b', x,y, rows, cols)
if (x==N-1) and (y==N-1):
pprint(rows)
return True
if (x+1 < N):
nextx=x+1
nexty=y
else:
nextx=0
nexty=y+1
if step(nextx,nexty,rows,cols,N) is True:
return True
rows[x].pop(-1)
cols[y].pop(-1)
return False
def build(N):
rows = [[] for i in range(0,N)]
cols = [[] for i in range(0,N)]
step(0,0,rows,cols,N)
My understanding is that the search string has to start with the first capital letter.
def check_a_string(s, d):
def nextup(d, di):
while d[di].islower():
di += 1
if di >= len(d):
return -1
return di
di = 0
#first char has to match
if s[0] != d[0]:
return False
for c in s[1:]:
if c.isupper():
di = nextup(d, di)
else:
di += 1
if (di == -1) or (c != d[di]):
return False
return True
def check(input, l):
for s in l:
if check_a_string(input, s):
yield s
l = ['HelloMars', 'HelloWorld', 'HelloWorldMars', 'HiHo']
search_strings = ["H", "HW", "Ho", "HeWorM"]
for t in search_strings:
result = list(check(t, l))
print(t)
print(result)
create a trie with the dictionary
- chromehearts July 29, 2016