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
charToMorse :: Char -> [Char] | |
charToMorse x | |
| x == ' ' = " " -- U+0020 | |
| x == '!' = "-.-.--" -- U+0021 | |
| x == '"' = ".-..-." -- U+0022 | |
| x == '&' = ".-..." -- U+0026 | |
| x == '\'' = ".----." -- U+0027 | |
| x == '(' = "-.--." -- U+0028 | |
| x == ')' = "-.--.-" -- U+0029 | |
| x == '+' = ".-.-." -- U+002B |
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 cv2 | |
def concat_frames_into_video(filename, frames, fps): | |
height, width, channels = frames[0].shape | |
fourcc = cv2.VideoWriter_fourcc(*'mp4v') | |
out = cv2.VideoWriter(filename, fourcc, fps, (width, height)) | |
for frame in frames: | |
out.write(frame) |
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 cv2 | |
def split_video_into_frames(filename): | |
frames = [] | |
cap = cv2.VideoCapture(filename) | |
fps = cap.get(cv2.CAP_PROP_FPS) | |
success = 1 | |
while success: | |
success, frame = cap.read() |
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 distance(a: list[int], b: list[int]) -> list[int]: | |
assert len(a) == len(b), "Coordinates must be in same dimension." | |
return [abs((a[i] - b[i])) for i in range(len(a))] |
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 | |
def distance(a: list[int], b: list[int]) -> list[int]: | |
assert len(a) == len(b), "Coordinates must be in same dimension." | |
return math.sqrt(sum([(a[i] - b[i])**2 for i in range(len(a))])) |
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 generate_subarrays(a: list[any]) -> list[any]: | |
return [a[i:j] for i in range(len(a)) for j in range(i + 1, len(a) + 1)] |
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"))) |
NewerOlder