This file contains 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
def moore(x, y, lower_x, lower_y, upper_x, upper_y): | |
neighbours = [(i, j) for i, j in ((x-1, y-1), (x, y-1), (x+1, y-1), (x-1, y), (x+1, y), (x-1, y+1), (x, y+1), (x+1, y+1)) if lower_x<=i<upper_x and lower_y<=j<upper_y] | |
return neighbours | |
def von_Neumann(x, y, lower_x, lower_y, upper_x, upper_y): | |
neighbours = [(i, j) for i, j in ((x, y-1), (x-1, y), (x+1, y), (x, y+1)) if lower_x<=i<upper_x and lower_y<=j<upper_y] | |
return neighbours |
This file contains 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 math | |
x = 99 # Select a starting point here | |
i = 0 | |
running = True | |
while running: | |
i += 1 | |
if x % 2 == 0: | |
x = x / 2 |
This file contains 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 random # Since the generation of this maze is random, I need the random module. | |
def generate_maze(x_cells, y_cells): | |
#x_cells = 20 # This defines the number of cells in the x-direction. | |
#y_cells = 20 # This defines the number of cells in the y-direction. | |
grid = [] # This allows me to build the grid from which the maze is generated. | |
for y in range(y_cells): | |
row = [] # Creates a 'row' list for all y locations (10 rows) | |
for x in range(x_cells): |
This file contains 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
class Stack: | |
def __init__(self): | |
self.stack = [] | |
self.stacklen = int(input(print("How long should the stack be?"))) | |
def push(self): | |
if len(self.stack) == self.stacklen: | |
self.full() | |
else: | |
self.stack.append(int(input("Enter a value to append.\n"))) |