Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@whong92
whong92 / GraphColoring.py
Created July 12, 2020 22:51
A simple program to solve a k-coloring of a N-hypercube graph (containing 2^N vertices), such that every vertex's neighbors (including each vertex inself) contain all colors [0,N-1].
from pprint import pprint
from collections import defaultdict
import numpy as np
from typing import List
class Node:
"""[
Object representing a node in the hypercube graph
Has a binary coordinate b and a color c
]
@whong92
whong92 / timestampSim.py
Created January 2, 2019 13:37
A short script of tools used to calculate lamport/vector clock timestamps for different events in a simulated distributed process
import numpy as np
class node:
"""
Node class to model the events as nodes in a graph.
Have parent and child pointers, a node id (unique integer) and a process id
Has a timestamp (ts) attribute which can be set by the BFS
"""
def __init__(self):
self.id = None
@whong92
whong92 / simpleChord.py
Created December 28, 2018 23:10
Short python script of a simplified simulation of Chord P2P Distributed Hash Table (DHT) system. Contains functions to build the ring and simulate a search path in the DHT when a query from a peer (node) is given.
from pprint import pprint
def binarySearch(alist, item):
"""
binary search given alist and item to search for
returns is element was found, otherwise return the last midpoint before search failed
last midpoint is always either the predessecor or succesor to item (if the item is not found)
"""
first = 0
last = len(alist)-1