Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def in_center(node, n):
- return node > n - 1 and node % n != 0 and (node + 1) % n != 0 and node < n*(n-1)
- n = 4
- nodes = []
- operations = [n, -n, 1, -1]
- center_nodes = []
- for i in range(0, n*n):
- if in_center(i, n):
- center_nodes.append(i)
- node = random.choice(center_nodes)
- nodes.append(node)
- while in_center(node, n):
- operation = random.choice(operations)
- next_node = node + operation
- if next_node > 0 and next_node < n * n and next_node not in nodes:
- nodes.append(next_node)
- node = next_node
- print(nodes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement