{{ message }}

Instantly share code, notes, and snippets.

# Peter Hayes peterkhayes

Last active Aug 29, 2015
monte carlo solution
View montecarlo.js
This file contains 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 integrate = function() { // return 42; var iters = 2000; var d = getGraphDimensions(); var width = d.x.max - d.x.min; var height = d.y.max - d.y.min; var xmin = d.x.min;
Created May 20, 2014
Making-Change problem with Dynamic Programming
View Description
This file contains 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
 // We write the problem as a table. Each row represents the amount of change to make, // and the value at each column represents the highest coin we're allowed to use // in making that amount of change // That is to say, in row 5, col 2 is the number of ways to make 5 cents, using only the two lowest coins. // To calculate the value of each square, we add the values of two other squares together - // * The square to the left, which represents all possibilites using smaller coins. // * The square as many rows above as the value of that coin. // This is all possibilities after taking away one of this coin // This method avoids having to ever call things recursively - we just build a big table!
Last active Aug 29, 2015
View gist:2276e305ff74cce8131e
This file contains 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
 On schoolTeacher resource: { _items: [ { _id: 1234 ... _links: { befriend/poolWith/etc: { href: "/api/teacher/1234/friends", method: "POST",
Last active May 6, 2016
Lecture notes for Intermediate Data Structures talk
View gist:fcb7548ef7cde329c460
This file contains 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) About me: a) Peter Hayes, engineer at ClassDojo b) Studied mathematical economics at Brown, used to be a high school math teacher c) Follow me on github/check out my npm. don't follow my twitter II) Introduction a) Topics today: heaps, quadtrees, graphs b) What are data structures for? 1) Not just to store data - an unstructured blob can store data 3) Rather: store data with *efficient* insertion, access, and retrieval
Created May 3, 2017
Javascript Disjoint Set
View disjointSet.js
This file contains 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
 /* Useful for HackerRank problems. */ function main (numNodes, edges) { const parent = []; const rank = []; function makeSet (x) {