finish level5/expanding-nebula #6
@ -6,9 +6,12 @@ def solution(g):
|
|||||||
#print grid
|
#print grid
|
||||||
height, width = grid.shape
|
height, width = grid.shape
|
||||||
#print height, width
|
#print height, width
|
||||||
|
|
||||||
|
prev_cases = {i:1 for i in generate_prev_cases(grid[:,0])}
|
||||||
|
#prev_cases = {i:1 for i in range(2**(len(column)+1))}
|
||||||
|
#print prev_cases
|
||||||
|
|
||||||
memo = {}
|
memo = {}
|
||||||
prev_cases = {i:1 for i in range(2**(height+1))}
|
|
||||||
#for i in range(2**(height+1)):
|
#for i in range(2**(height+1)):
|
||||||
# prev_cases[i] = 1
|
# prev_cases[i] = 1
|
||||||
# memo[i] = {j:calculate_c_column(i, j, height) for j in range(2**(height+1))}
|
# memo[i] = {j:calculate_c_column(i, j, height) for j in range(2**(height+1))}
|
||||||
@ -33,6 +36,24 @@ def solution(g):
|
|||||||
prev_cases = cases
|
prev_cases = cases
|
||||||
return sum(prev_cases.values())
|
return sum(prev_cases.values())
|
||||||
|
|
||||||
|
def generate_prev_cases(column):
|
||||||
|
#print column
|
||||||
|
if len(column) == 0:
|
||||||
|
yield 0
|
||||||
|
yield 1
|
||||||
|
else:
|
||||||
|
for v in generate_prev_cases(column[:-1]):
|
||||||
|
#print 'v', v
|
||||||
|
if column[len(column)-1] and v&1 == 1:
|
||||||
|
yield v<<1|0
|
||||||
|
else:
|
||||||
|
yield v<<1|0
|
||||||
|
yield v<<1|1
|
||||||
|
|
||||||
|
#for t in [[True], [False], [True, True], [True, False], [False, True], [False, False]]:
|
||||||
|
# print 'run', t, list(generate_prev_cases(t))
|
||||||
|
#exit(0)
|
||||||
|
|
||||||
def print_grid(g):
|
def print_grid(g):
|
||||||
for row in g:
|
for row in g:
|
||||||
line = ""
|
line = ""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user