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
<?php | |
class SharedArray extends Stackable { | |
public function __construct($array) { | |
$this->merge($array); | |
} | |
public function run(){} | |
} |
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
<?php | |
$a = array(1,2,5,9,8,7,4,5,6,5,8,15,10,25,85,4,1,2,78,9); | |
function qsort(array &$a, $low, $high) | |
{ | |
if ($low < $high){ | |
$pivot = partition($a, $low, $high); | |
qsort($a, $low, $pivot - 1); | |
qsort($a, $pivot + 1, $high); |
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
<?php | |
trait Singleton | |
{ | |
private static $_instance = null; | |
public static function getInstance() | |
{ | |
if (is_null(self::$_instance)) { | |
self::$_instance = new static(); |
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
#!/usr/bin/env python | |
import sys | |
def main(list): | |
dict = {} | |
if len(list) == 0: | |
return None | |
common = list[0] | |
for element in list: |
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
#!/usr/bin/env python | |
import sys | |
def main(list): | |
dict = {} | |
memo = unique = set() | |
if len(list) == 0: | |
return None |
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
#!/usr/bin/env python | |
import sys | |
import networkx as nx | |
from collections import deque | |
def bfs(graph): | |
queue = deque([]) | |
queue.append(graph.nodes()[0]) |
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 sys | |
def quicksort(list, lo=None, hi=None): | |
if lo is None: | |
lo, hi = 0, len(list)-1 | |
if lo < hi: | |
pivot = partition(list, lo, hi) | |
quicksort(list, lo, pivot-1) | |
quicksort(list, pivot + 1, hi) |
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
def binsearch(needle, haystack): | |
lo, hi, found = 0, len(haystack)-1, None | |
while lo <= hi and found is None: | |
mid = lo + (hi - lo) // 2 | |
if haystack[mid] == needle: | |
found = mid | |
if haystack[mid] < needle: | |
lo = mid + 1 | |
else: | |
hi = mid - 1 |
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
def pascal_triangle(n): | |
prev = [] | |
for row in xrange(n): | |
curr = [1] | |
for index in xrange(1, row): | |
curr.append(prev[index-1] + prev[index]) | |
if row > 0: curr.append(1) | |
print curr | |
prev = curr |
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
def lcs_length(a, b): | |
table = [[0] * (len(b) + 1)] * (len(a) + 1) | |
for i, ca in enumerate(a, 1): | |
for j, cb in enumerate(b, 1): | |
table[i][j] = ( | |
table[i - 1][j - 1] + 1 if ca == cb else | |
max(table[i][j - 1], table[i - 1][j])) | |
return table[-1][-1] |
OlderNewer