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
import Foundation | |
func emptyGenerator<T>() -> AnyGenerator<T> { | |
return anyGenerator{ | |
return nil | |
} | |
} | |
func generateOnce<T>(g: () -> T) -> AnyGenerator<T> { | |
var first = true |
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
import Foundation | |
public protocol KDPoint { | |
func distance(other: Self) -> Double | |
func dimension() -> Int | |
func lessThan(other: Self, dim: Int) -> Bool | |
} | |
public enum BinaryTreeVisitOrder { | |
case InOrder |
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
from graph import * | |
def kosaraju(g): | |
def dfs(g, start, s, visited=set()): | |
for n in g.vertex_out[start]: | |
if n in visited: continue | |
visited.add(n) | |
dfs(g, n, s, visited) | |
s.append(start) | |
from random import sample |
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
class DirectedGraph: | |
def __init__(self, edges={}): | |
# copy/cast constructor | |
if isinstance(edges, DirectedGraph): edges = edges.label | |
self.label = {} | |
self.vertex_in = {} | |
self.vertex_out = {} | |
for edge, label in edges.items(): | |
self[edge] = label |
NewerOlder