Skip to content

Instantly share code, notes, and snippets.

View i143code's full-sized avatar

ashish ranjan i143code

  • Boston, MA
View GitHub Profile
@i143code
i143code / KABF-0.py
Created August 7, 2017 14:00
null created by i143code - https://repl.it/KABF/0
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']
@i143code
i143code / Linked List Python.py
Created August 4, 2017 21:48
Linked List Python created by i143code - https://repl.it/Jxdj/0
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
@i143code
i143code / Prime Number.py
Created August 4, 2017 21:28
Prime Number created by i143code - https://repl.it/Jxck/0
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):
@i143code
i143code / Legendary Entrtainment .js
Created July 31, 2017 19:31
Legendary Entrtainment created by i143code - https://repl.it/JqV5/26
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]);
}
@i143code
i143code / Legendary Entrtainment .js
Created July 31, 2017 19:25
Legendary Entrtainment created by i143code - https://repl.it/JqV5/24
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]);
}
@i143code
i143code / BST Javascript.js
Created July 29, 2017 03:07
BST Javascript created by i143code - https://repl.it/JnbN/5
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
@i143code
i143code / Depth first search .py
Created July 14, 2017 03:25
Depth first search created by i143code - https://repl.it/J12o/16
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
@i143code
i143code / bfs.py
Created July 14, 2017 03:08
null created by i143code - https://repl.it/J104/10
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 = []
@i143code
i143code / fizzbuzz.py
Created July 8, 2017 03:10
null created by i143code - https://repl.it/JSj6/0
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)
@i143code
i143code / String Permutation.py
Created July 5, 2017 17:14
String Permutation created by i143code - https://repl.it/JOsy/1
def permute(s):
out = []
# Base Case
if len(s) == 1:
out = [s]
else:
# For every letter in string
for i, let in enumerate(s):