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 cartesian_iterative(pools): | |
result = [[]] | |
for pool in pools: | |
result = [x+[y] for x in result for y in pool] | |
return result | |
somelists = [ | |
['grey','black'], | |
['fox','dog'], | |
['jumped','ran','growled'] |
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
class Node(object): | |
def __init__(self,data): | |
self.data = data | |
self.next = None | |
class LinkedList(object): | |
def __init__(self): | |
self.head = None | |
self.tail = None | |
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 isPrime(n): | |
if n == 2: | |
return True | |
if n < 2 or n & 1: | |
print("The list") | |
print(n) | |
print("End list") | |
return False | |
for i in range(3, int(n**0.5)+1,2): |
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, edges) { | |
this.vertices = []; | |
this.edges = []; | |
this.numberOfEdges = nodes; | |
for (var i = 0; i < nodes; i++) { | |
this.addVertex(i); | |
} | |
for (var i = 0; i < edges.length; i++) { | |
this.addEdge(edges[i][0], edges[i][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
function Graph(nodes, edges) { | |
this.vertices = []; | |
this.edges = []; | |
this.numberOfEdges = nodes; | |
for (var i = 0; i < nodes; i++) { | |
this.addVertex(i); | |
} | |
for (var i = 0; i < edges.length; i++) { | |
this.addEdge(edges[i][0], edges[i][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
function BST(value){ | |
this.value = value | |
this.left = null | |
this.right = null | |
} | |
// create binary serach tree | |
BST.prototype.insert = function(value){ | |
if (value < this.value){ | |
// no left chile |
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
class Node(object): | |
def __init__(self,data): | |
self.data = data | |
self.adjacent = [] | |
self.visited = False | |
class DeapthFirstSearch(object): | |
# recursive | |
def dfs(self,node): | |
node.visited = True |
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
class Node(object): | |
def __init__(self,data): | |
self.data = data | |
self.adjacent = [] | |
self.visited = False | |
# breadth first search | |
class BreadthFirstSSearch(object): | |
def bfs(self,startNode): | |
queue = [] |
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 fizzbuzz(n): | |
if n % 3 == 0 and n % 5 == 0: | |
return 'FizzBuzz' | |
elif n % 3 == 0: | |
return 'Fizz' | |
elif n % 5 == 0: | |
return 'Buzz' | |
else: | |
return str(n) |
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 permute(s): | |
out = [] | |
# Base Case | |
if len(s) == 1: | |
out = [s] | |
else: | |
# For every letter in string | |
for i, let in enumerate(s): |
NewerOlder