Skip to content

Instantly share code, notes, and snippets.

View melwyn95's full-sized avatar
🐫
OCaml

Melwyn Saldanha melwyn95

🐫
OCaml
View GitHub Profile
@melwyn95
melwyn95 / BT_max_sum_path.js
Last active September 11, 2020 13:55
Interesting Leetcode Problems
/**
*
* -10
/ \
9 20
/ \
15 7
*
*
@melwyn95
melwyn95 / index.ts
Created July 20, 2020 05:45
AVL Tree
type AVLNode<T> = {
left: AVLNode<T>,
right: AVLNode<T>,
val: T,
height: number
} | null;
type CompareResult = -1 | 0 | 1;
function compare<T>(x: T, y: T): CompareResult {
@melwyn95
melwyn95 / spiral_walk.js
Created July 7, 2020 10:30
Spiral traversal
const arr_odd = [
[1, 2, 3, 4, 5],
[16, 17, 18, 19, 6],
[15, 24, 25, 20, 7],
[14, 23, 22, 21, 8],
[13, 12, 11, 10, 9]
];
const arr_even = [
[1, 2, 3, 4, 5, 6],
@melwyn95
melwyn95 / json_parser.js
Last active July 2, 2020 17:16
JSON parser
// TOKEN types
const COLON = 'COLON';
const L_CURLY = 'L_CURLY';
const R_CURLY = 'R_CURLY';
const L_SQUARE = 'L_SQUARE';
const R_SQUARE = 'R_SQUARE';
const COMMA = 'COMMA';
const BOOLEAN_LITERAL = 'BOOLEAN_LITERAL';
const NUMBER_LITERAL = 'NUMBER_LITERAL';
@melwyn95
melwyn95 / go_routine.go
Last active May 27, 2020 08:34
Golang for Microservices
package main
//Result deines the result of a Computation
type Result struct {
product int
row, col int
}
//Compute take a Compuataion as input and writes the Result on to a channel
func Compute(row, col int, rowSlice, colSlice []int, out chan<- Result) {
@melwyn95
melwyn95 / App.js
Created May 5, 2020 12:03
Recursive Squares + Random color generator
function ColorGenerator() {
let index = 0;
const colors = ["red", "green", "blue", "yellow", "black", "white"];
const rand = (s, e) => Math.random() * (e - s + 1);
return {
generate: () => colors[index++ % colors.length],
generateRGB: () => `rgb(${rand(0, 255)}, ${1}, ${rand(0, 255)})`
};
@melwyn95
melwyn95 / flatten.js
Last active March 28, 2020 18:07
Array Flattening (Iterative Version)
function flatten(xs) {
var ys = [];
var stack = [[0, xs]];
while(stack.length > 0) {
var [index, arr] = stack.pop();
while(index < arr.length) {
if (Array.isArray(arr[index])) {
stack.push([index+1, arr]);
function flatten(xs) {
var itr = xs;
while (true) {
var ys = [];
var allFlat = true;
itr.forEach(x => !(allFlat = (!Array.isArray(x) && allFlat)) ? (ys = ys.concat(x)) : ys.push(x));
if (allFlat) return ys;
itr = ys;
}
}
@melwyn95
melwyn95 / index.html
Last active March 8, 2020 15:10
Snake Pub Sub
<!DOCTYPE html>
<html>
<head>
<title>Snake Pub Sub</title>
</head>
<body>
<canvas id="canvas" height="500" width="500">
@melwyn95
melwyn95 / _list.md
Last active September 12, 2020 03:09
Fractals and Automatons
  1. Koch Snowflake
  2. Toothpick Pattern
  3. Ulam Warburton Cellular Automaton
  4. Hilbert's Curve