Skip to content

Instantly share code, notes, and snippets.

View talhaahussain's full-sized avatar
🌑
In orbit...

Talhaa Hussain talhaahussain

🌑
In orbit...
View GitHub Profile
@talhaahussain
talhaahussain / the-dangers-of-generative-AI.md
Last active May 9, 2024 13:52
the-dangers-of-generative.AI.md -- Continuous Assessment for ECM2427 - Outside the Box: Computer Science Research and Applications (Year 2, Semester 2). A short report on the dangers of generative artificial intelligence. This work received a final mark of 72/100.

ECM2427_Coursework_page-0001 ECM2427_Coursework_page-0002 ECM2427_Coursework_page-0003 ECM2427_Coursework_page-0004

@talhaahussain
talhaahussain / stack.py
Last active June 4, 2024 02:00
stack.py -- An object-oriented, first principles implementation of a stack data structure, written in Python.
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")))
@talhaahussain
talhaahussain / maze-algorithm.py
Created May 25, 2024 13:00
maze-algorithm.py -- A simple, flexible maze generation algorithm implemented in Python. See the original and an application here: https://github.com/talhaahussain/maze-game/
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):
@talhaahussain
talhaahussain / collatz.py
Created May 28, 2024 07:27
collatz.py -- A very simple demonstration of the Collatz conjecture, an unsolved problem in mathematics, in Python. Applies the rules of the conjecture in a repeated loop on some integer x, and outputs the number of steps taken to reach 1.
import math
x = 99 # Select a starting point here
i = 0
running = True
while running:
i += 1
if x % 2 == 0:
x = x / 2
@talhaahussain
talhaahussain / find_neighbours.py
Last active May 30, 2024 22:13
find_neighbours.py -- A simple, elegant way of finding all neighbours for a cell in a grid, using the Moore neighbourhood or the von Neumann neighbourhood. Assumes an inclusive lower bound and exclusive upper bound for x and y. Useful for cellular automata.
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