SHARE
TWEET

Untitled

a guest Nov 19th, 2019 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2.  
  3. def in_center(node, n):
  4.     return node > n - 1 and node % n != 0 and (node + 1) % n != 0 and node < n*(n-1)
  5.  
  6. n = 4
  7. nodes = []
  8. operations = [n, -n, 1, -1]
  9.  
  10. center_nodes = []
  11. for i in range(0, n*n):
  12.     if in_center(i, n):
  13.        center_nodes.append(i)
  14. node = random.choice(center_nodes)
  15. nodes.append(node)
  16. while in_center(node, n):
  17.     operation = random.choice(operations)
  18.     next_node = node + operation
  19.     if next_node > 0 and next_node < n * n and next_node not in nodes:
  20.         nodes.append(next_node)
  21.         node = next_node
  22.  
  23. print(nodes)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top