This file contains hidden or 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
# /// script | |
# dependencies = [ | |
# "libcst", | |
# ] | |
# /// | |
""" | |
Author: https://github.com/f0lie | |
This script added explicit encoding of UTF-8 to open(...) for both read and writes. |
This file contains hidden or 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
# https://stackabuse.com/minimax-and-alpha-beta-pruning-in-python/ | |
# Changes include: | |
# 1. Reducing the amount of code for looking for end of the game | |
# 2. Allow for boards of N size. But the game is impossible to play | |
# because it takes too long to find the optimial moves even with | |
# alpha beta pruning. | |
import time | |
from collections import namedtuple | |
from typing import List, Tuple, Optional |
This file contains hidden or 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
from collections import defaultdict, deque | |
import heapq | |
from typing import OrderedDict | |
def create_graph(matrix): | |
graph = defaultdict(list) | |
for row in range(len(matrix)): | |
for col in range(len(matrix[0])): | |
if matrix[row][col] > 0: |
This file contains hidden or 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 Node: | |
def __init__(self, val=0, next=None): | |
self.next = next | |
self.val = val | |
def __repr__(self): | |
# Note that __repr__ is meant to be able "copy and paste" into the console and create itself | |
return f"Node({self.val}, {self.next})" | |
if __name__ == "__main__": |
This file contains hidden or 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
#include <iostream> | |
#include <vector> | |
#include <exception> | |
#include <memory> | |
#include <algorithm> | |
//https://gist.github.com/f0lie/fc213e1047c4ca9f829b58c41f91091f | |
template<typename Key, typename T> | |
//class bst { | |
private: |
This file contains hidden or 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
# https://albertauyeung.github.io/2020/06/15/python-trie.html | |
# Mainly this but I added some neat features and simplified some parts | |
class Trie: | |
class Node: | |
def __init__(self, char): | |
self.char = char | |
self.children = {} | |
# If true it marks the end of a string | |
# If this isn't here, then we couldn't have overlapping nodes like "change" and "cha" |
This file contains hidden or 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
// https://gist.github.com/f0lie/ae376ff51834479e3a139b68c3a4cbea | |
#include <memory> | |
#include <exception> | |
template <typename T> | |
//class deque { | |
struct node { | |
T data; | |
// Do not use a shared pointer when a plain pointer can be used. | |
// Unique ptrs represent ownership. You can't just add them everywhere. |
This file contains hidden or 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
""" | |
I did this for a discrete math class problem. | |
Basically find the mode of an array recursively. Fun little problem. | |
Use this to understand a basic example of recursion | |
""" | |
def find_mode(array): | |
if len(array) == 1: | |
return array[0] | |
num = array.pop() |
This file contains hidden or 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
"" | |
I basically implemented MIT 6.0006 Heap lesson. | |
https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-006-introduction-to-algorithms-fall-2011/lecture-notes/ | |
I stole the index bits from wikipedia. | |
Mit used arrays starting at 1. | |
Stole the printing function from: | |
https://hbfs.wordpress.com/2016/12/06/pretty-printing-a-tree-in-a-terminal/ | |
""" | |
from collections import deque |