Created
March 20, 2018 01:30
-
-
Save fortable1999/9315cf3d09b9f1d51316666d1328705c to your computer and use it in GitHub Desktop.
algorithm program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import copy | |
COUNT = 0 | |
M = 4 | |
N = 4 | |
def print_current_jumps(mx): | |
for line in mx: | |
print(line) | |
print('=============') | |
def get_next_jump(mx, x, y, max_x, max_y): | |
assert(mx[x][y]==1) | |
jumps = [] | |
if x != 0 and mx[x-1][y] != 1: | |
jumps.append([x-1, y]) | |
if x+1 < max_x and mx[x+1][y] != 1: | |
jumps.append([x+1, y]) | |
if y != 0 and mx[x][y-1] != 1: | |
jumps.append([x, y-1]) | |
if y+1 < max_y and mx[x][y+1] != 1: | |
jumps.append([x, y+1]) | |
return jumps | |
def one_step(mx, x, y, max_x, max_y): | |
assert(mx[x][y]==0) | |
mx[x][y] = 1 | |
print_current_jumps(mx) | |
next_jumps = get_next_jump(mx, x, y, max_x, max_y) | |
if not next_jumps: | |
if sum([i for i in [sum(j) for j in mx]]) == max_x * max_y: | |
print("FINISHED!") | |
global COUNT | |
COUNT += 1 | |
else: | |
print("NOT THIS ONE") | |
for j in next_jumps: | |
one_step(copy.deepcopy(mx), j[0], j[1], max_x, max_y) | |
def init(m, n): | |
mx = [[0] * n for i in range(m)] | |
one_step(mx, 0, 0, m, n) | |
if __name__ == '__main__': | |
init(M, N) | |
print(COUNT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment