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
/** | |
* Binary Search Tree | |
* | |
* This is a tree data structure that orders the nodes of the tree such that: | |
* - The left subtree only contains nodes of lesser values | |
* - The right subtree only contains nodes of greater values | |
* - There are no duplicate nodes | |
* | |
* What this is good for: | |
* - Storing unique values |
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
/** | |
* echo server | |
* | |
*/ | |
var net = require('net'), | |
port = 5000, | |
unixsocket = '/tmp/echo.sock'; | |
var log = function(who, what) { |
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
var bitwiseOR = function() { | |
// for each bit, if there is a "1" in the place, then the bit becomes "1" | |
var a = parseInt('00001111', 2); | |
var b = parseInt('11110000', 2); | |
var c = a | b; | |
c.toString(2); // '11111111' | |
// when the binary number is not the same length, 0's are added to the front | |
var d = parseInt('11110000', 2); | |
var e = parseInt('1100', 2); // becomes '00001100' |
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
/* | |
* Binary Heap | |
* | |
* This is a heap which is built on top of a binary tree. The binary tree can | |
* be built using a regular array and some arithmetic to find the array indicies | |
* of a particular node's children. | |
* | |
* The Binary Heap is a 'complete tree', meaning that all levels of the tree are | |
* completely filled before going deeper. The levels of the tree are filled from | |
* left to right. |
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
var Set = function() { | |
this._items = {}; | |
}; | |
Set.prototype = { | |
values: function() { | |
return Object.keys(this._items); | |
}, | |
insert: function(val) { |
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
// quick sort | |
// https://en.wikipedia.org/wiki/Quicksort | |
var sort = function(list) { | |
if (list.length <= 1) return list; | |
var pivot = list.splice(Math.floor(list.length / 2), 1); | |
var less = [], greater = []; | |
while (list.length) { |
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
// merge sort | |
// https://en.wikipedia.org/wiki/Merge_sort | |
var sort = function(list) { | |
// if list contains one element, it is sorted | |
if (list.length <= 1) return list; | |
// divide list in half into 2 sublists | |
var middle = Math.floor(list.length / 2); | |
var left = list.slice(0, middle); |
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
function Graph(nodes) { | |
this.nodes = nodes || {}; | |
} | |
Graph.prototype.print = function(storage, start, stop) { | |
start = start || 1; | |
storage.put(new Node(start)); | |
while (! storage.isEmpty()) { | |
var seen = {}; |
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
/* | |
borrowed: | |
- IR code/library from http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html | |
- ultrasonic sensor code from http://arduino.cc/en/Tutorial/Ping | |
*/ | |
#include <IRremote.h> | |
#include <Servo.h> | |
// pins pins pins |
NewerOlder