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
import numpy as np | |
import gym | |
def sigmoid(x): | |
return 1.0 / (1.0 + np.exp(-x)) | |
env = gym.make('CartPole-v1') | |
desired_state = np.array([0, 0, 0, 0]) | |
desired_mask = np.array([0, 0, 1, 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 Graph(object): | |
''' | |
Undirected Graph | |
INPUT: | |
Node Count: Int | |
Edges: List in format [source, end] | |
''' | |
def __init__(self,n,edges): | |
self.nodeCount = n | |
self.label = list(range(n)) |
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
''' | |
Implement a Disjoint Set Data Structure Using Path Compression and Balancing | |
''' | |
class disjointSet: | |
def __init__(self, n): | |
self.parent = list(range(n)) | |
self.rank = [0] * n | |
def find(self, element): |
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
# Extended the class to address previous comments: a) redundant inserts, b) delete method | |
class Node: | |
def __init__(self, val): | |
self.val = val | |
self.parent = None | |
self.__left = None | |
self.__right = None | |
self.code = 3 | |