Skip to content

Instantly share code, notes, and snippets.

View lykkin's full-sized avatar
🐄
Moo

Bryan Clement lykkin

🐄
Moo
View GitHub Profile
@lykkin
lykkin / gist:ff19b41b1d65cd0195f5
Created July 16, 2015 18:03
disjoint set stuff
// 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
}
@lykkin
lykkin / gist:9831f8bb88eccd1a61e1
Created July 7, 2015 21:28
closure based caching
'use strict'
function Obj() {}
Obj.prototype.getVal = getVal
Obj.prototype.clearCache = function clearCachedVal() {
console.log('clearing the cache')
this.getVal = getVal
}
@lykkin
lykkin / javascript.js
Last active December 8, 2015 02:05
first pass of zero knowledge password auth, also some rsa or whatever
'use strict'
function generate_base_pair() {
const first = generate_prime()
var second = null
while (second === null || second === first) {
second = generate_prime()
}
return [first, second]
}
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
@lykkin
lykkin / gist:b4d0c5610e664485dad4
Last active August 29, 2015 14:21
weighted choice
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)
@lykkin
lykkin / gist:90a32ea4292934cefbf5
Last active August 29, 2015 14:18
permutations
from math import factorial
from functools import wraps
from datetime import datetime
class Profiler():
tracking = {}
def time(self, f):
#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++){
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)]
@lykkin
lykkin / blue.py
Created February 22, 2015 08:00
dumb markov thing
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
@lykkin
lykkin / gist:2a66f41bf79880b79432
Created February 15, 2015 18:47
tail call map
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 []))