Skip to content

Instantly share code, notes, and snippets.


Yogesh Drall YDrall

View GitHub Profile
View Generate all unique permutation of an array.
arr = [1, 2, 3, 4]
from collections import deque
qu = deque([[a] for a in range(len(arr))])
while qu:
q = qu.popleft()
print([arr[i] for i in q])
for j in range(q[-1]+1, len(arr)):
qu.append(q + [j])
View gcd, hcf, lcm
def gcd(a,b):
return a
def lcm(*args):
from functools import reduce
import math
return reduce(lambda a,b:(a*b)/math.gcd(int(a),int(b)), args)
View fib in different languages
def fibonacci(n):
print n
if n == 0 or n == 1:
return 1
return fibonacci(n-1) + fibonacci(n-2)
if __name__ == "__main__":
from sys import argv
YDrall / kmp.cpp
Created August 18, 2015 16:10
c++ implementation of kmp string matching algorithm.
View kmp.cpp
using namespace std;
int *pre_kmp(string pattern)
int size = pattern.size();
int *pie=new int [size];
pie[0] = 0;