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
test = [4,2,6,8,3,1,9,10,27,89,2] | |
from copy import deepcopy | |
def selection(lst): | |
N = len(lst) | |
for i in range(N): | |
for j in range(i,N): | |
if lst[j] < lst[i]: | |
lst[i],lst[j] = lst[j],lst[i] |
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
import math | |
from random import random | |
import collections | |
import functools | |
import logging | |
import sys | |
try: | |
level = sys.argv[1] | |
loglevel = getattr(logging,level) |
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, key, parent=None): | |
self.key = key | |
self.parent = parent | |
self.left = None | |
self.right = None | |
def has_children(self): return len(self) > 0 | |
def delete(self, node): |
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 Dummy(object): | |
def __init__(self,foo): | |
self.foo = foo | |
def __len__(self): | |
#This will make me always falsy, define and __nonzero__ method! | |
return 0 | |
def __gt__(self,other): |
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
sieve = [x for x in range(2,i) if not [t for t in range(2,x) if not x%t]] |
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 BloomSet[A] private (val size: Int, val k: Int,private val contents: Vector[Boolean]){ | |
val width = contents.length | |
def this(width: Int, k: Int) = this(0, k, BloomSet.alloc(width)) | |
def contains(e:Any) = { | |
(0 to k).foldLeft(true) { (acc,i) => | |
acc && contents(hash(e,i,width)) | |
} |
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
cases = [ | |
([2,2,-1],True), | |
([3,1,2,-2],True), | |
([-4,2,4],False), | |
([9,8,8],False) | |
] | |
def is_circular_complete(case): | |
key = 0 | |
size = len(case) |
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
package com.heap; | |
import util.control.Breaks._; | |
import collection.mutable._; | |
abstract class Heap(){ | |
var table = ArrayBuffer[Char](); | |
var N:Int = -1; | |
def +=(value:Char) = { | |
N = N+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
ints = [int(x) for x in open('IntegerArray.txt').read().split()] | |
def merge_and_count(a, b): | |
assert a == sorted(a) and b == sorted(b) | |
c = [] | |
count = 0 | |
i, j = 0, 0 | |
while i < len(a) and j < len(b): | |
c.append(min(b[j], a[i])) | |
if b[j] < a[i]: |
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
from cherrypy.process.plugins import Daemonizer,PIDFile | |
import cherrypy | |
import argparse | |
parser = argparse.ArgumentParser(description="My server daemon") | |
parser.add_argument('-d','--daemon',help='Run the server as a daemon using the traditional double fork',action='store_true') | |
parser.add_argument('-a','--bind-address',help='Network interface to bind to',default='127.0.0.1') | |
parser.add_argument('-p','--port',help='Port to bind to',default=8080,type=int) | |
parser.add_argument('--pidfile',help='process id file',type=str) | |
args = parser.parse_args() |