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
// return the root of the tree, this is a static representative of the | |
// set that a node belongs to | |
function find(node) { | |
// track which nodes are on the path to the root, hang them off the | |
// root if they aren't already | |
var path = [] | |
while (node.parent !== node) { | |
if (node.parent.parent !== node.parent) path.push(node) | |
node = node.parent | |
} |
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
'use strict' | |
function Obj() {} | |
Obj.prototype.getVal = getVal | |
Obj.prototype.clearCache = function clearCachedVal() { | |
console.log('clearing the cache') | |
this.getVal = getVal | |
} |
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
'use strict' | |
function generate_base_pair() { | |
const first = generate_prime() | |
var second = null | |
while (second === null || second === first) { | |
second = generate_prime() | |
} | |
return [first, second] | |
} |
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
def output_board(board): | |
for row in board: | |
print ' '.join(map(str, row)) | |
def place_queen(board, coordinate): | |
new_board = [] | |
for row in board: | |
new_board.append(row[:]) | |
x,y = coordinate |
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
from random import random | |
class thing: | |
def __init__(self, value, weight=1): | |
self.value = value | |
self.weight = weight | |
def __str__(self): | |
return str(self.value) + ' ' + str(self.weight) |
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
from math import factorial | |
from functools import wraps | |
from datetime import datetime | |
class Profiler(): | |
tracking = {} | |
def time(self, f): |
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
#include <stdio.h> | |
#include <stdlib.h> | |
unsigned long long possibleSums(unsigned int n, unsigned long long* memo){ | |
if (n == 0) { return 1; } | |
if (memo[n] != 0) { return memo[n]; } | |
int i; | |
unsigned long long sum = 0; | |
int denoms[7] = {1,2,5,10,20,50,100}; | |
for(i = 0; i < 7; i++){ |
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
type Peg = String | |
type Move = (Peg, Peg) | |
hanoi :: Integer -> Peg -> Peg -> Peg -> [Move] | |
hanoi disks from to storage | disks > 1 = (hanoi (disks - 1) from storage to) ++ [(from, to)] ++ (hanoi (disks - 1) storage to from) | |
| otherwise = [(from, to)] |
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
from random import random | |
class node: | |
name = '' # the token's value | |
followingStates = None # <next name>: <num of times seen> | |
numSeen = 0 # number of times token has been seen | |
def __init__(self, name): | |
self.name = name | |
self.numSeen = 1 |
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
mapz f (x:xs) = (f x):(mapz f xs) | |
mapz f [] = [] | |
mapa f li = let mapacc f (x:xs) acc = mapacc f xs ((f x):acc) | |
mapacc f [] acc = acc | |
in | |
(reverse (mapacc f li [])) |