Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Wall Keeper by Kurush
def wall_keeper(on_panels):
lst = []
# original on_panels is used in the checker function.
copy_on_panels = on_panels.copy()
up_down_procedure(copy_on_panels, lst)
if copy_on_panels == []:
print (copy_on_panels, lst)
return lst
if 21 in copy_on_panels:
apply_move(4, copy_on_panels, lst)
apply_move(5, copy_on_panels, lst)
if 22 in copy_on_panels:
apply_move(2, copy_on_panels, lst)
apply_move(5, copy_on_panels, lst)
if 23 in copy_on_panels:
apply_move(4, copy_on_panels, lst)
up_down_procedure(copy_on_panels, lst)
print (copy_on_panels, lst)
return lst
def up_down_procedure(on_panels, lst):
for row in range(4):
for elem in range(1, 6):
light = row * 5 + elem
if light in on_panels:
apply_move(light + 5, on_panels, lst)
def apply_move(move, on_panels, lst):
lst.append(move)
if move not in on_panels: on_panels.append(move)
else: on_panels.remove(move)
if move + 1 <= 25 and move // 5 == (move - 1) // 5:
if move + 1 not in on_panels: on_panels.append(move + 1)
else: on_panels.remove(move + 1)
if move + 5 <= 25:
if move + 5 not in on_panels: on_panels.append(move + 5)
else: on_panels.remove(move + 5)
if move - 1 >= 1 and (move - 2) // 5 == (move - 1) // 5:
if move - 1 not in on_panels: on_panels.append(move - 1)
else: on_panels.remove(move - 1)
if move - 5 >= 1:
if move - 5 not in on_panels: on_panels.append(move - 5)
else: on_panels.remove(move - 5)
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary for auto-testing
from itertools import chain
def checker(solution, on_panels):
answer = solution(on_panels)
wk_p = list((0, 1)[n in on_panels] for n in range(1, 26))
p = list(wk_p[n: n+5] for n in range(0, 25, 5))
for a in answer:
r, c = (a-1) // 5, (a-1) % 5
p[r][c] = 1 - p[r][c]
if r+1 < 5:
p[r+1][c] = 1 - p[r+1][c]
if r-1 > -1:
p[r-1][c] = 1 - p[r-1][c]
if c+1 < len(p[0]):
p[r][c+1] = 1 - p[r][c+1]
if c-1 > -1:
p[r][c-1] = 1 - p[r][c-1]
return sum(chain(*p)) == 0
assert checker(wall_keeper, [5, 7, 13, 14, 18]), 'basic'
assert checker(wall_keeper, list(range(1, 26))), 'all_lights'
Feb. 23, 2019