Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
O(1) solution in Speedy category for Wall Keeper by Sim0000
index=(
(2, 3, 4, 8, 10, 14, 15, 20),
(1, 2, 4, 5, 7, 13, 14, 15, 19),
(1, 3, 4, 5, 6, 8, 9, 13, 14, 16, 17, 18, 19, 20, 22),
(1, 2, 3, 7, 17, 21, 22, 23),
(2, 3, 5, 6, 11, 13, 15, 18, 20, 21, 22),
(3, 5, 7, 8, 10, 13, 19, 20),
(2, 4, 6, 7, 9, 10, 14, 16, 17, 18, 22),
(1, 3, 6, 8, 9, 15, 16, 18, 20, 21, 23),
(3, 7, 8, 9, 11, 14, 15, 16, 19, 22, 23),
(1, 6, 7, 11, 13, 15, 17, 18, 20, 23),
(5, 9, 10, 13, 15, 16, 17, 18, 19, 22),
(17, 21, 22, 23),
(2, 3, 5, 6, 10, 11, 13, 14, 18, 21, 22),
(1, 2, 3, 7, 9, 13, 14, 15, 19),
(1, 2, 5, 8, 9, 10, 11, 14, 15, 16, 17, 19, 21),
(3, 7, 8, 9, 11, 15, 16, 18, 20, 21, 23),
(3, 4, 7, 10, 11, 12, 15, 17, 18, 19, 23),
(3, 5, 7, 8, 10, 11, 13, 16, 17, 19, 20, 21),
(2, 3, 6, 9, 11, 14, 15, 17, 18, 19, 23),
(1, 3, 5, 6, 8, 10, 16, 18, 20, 21, 23),
(4, 5, 8, 12, 13, 15, 16, 18, 20, 21, 22),
(3, 4, 5, 7, 9, 11, 12, 13, 21, 22, 23),
(4, 8, 9, 10, 12, 16, 17, 19, 20, 22)
)
def wall_keeper(wall):
return [i + 1 for i in range(23) if sum(j in wall for j in index[i]) & 1]
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'
March 15, 2017
Comments: