Skip to content

Instantly share code, notes, and snippets.

View tiggreen's full-sized avatar
🤖

Tigran Hakobyan tiggreen

🤖
View GitHub Profile
@tiggreen
tiggreen / permuts.py
Last active August 29, 2015 14:01
All the permutations for the given string.
#Author @tiggreen
#Print all the permutations of the given string
def insertEverywhere(c, s):
retList = []
for i in range(len(s) + 1):
temp = s[:i] + c + s[i:]
retList.append(temp)
return retList
@tiggreen
tiggreen / InsertionSort.py
Created May 13, 2014 18:11
Insertion sort in Python
#Author: @tiggreen
def insertionSort(lst):
for i in range(1, len(lst)):
j = i
while (j > 0 and lst[j-1] > lst[j]):
lst[j-1], lst[j] = lst[j], lst[j-1]
j = j-1
return lst
@tiggreen
tiggreen / LinkedList.py
Last active August 29, 2015 14:01
insertAt function for a LinkedList in Python.
#Author: @tiggreen
class LinkedList():
__slots__ = ('head', 'size')
class Empty():
__slots__= ()
class NonEmpty():
__slots__= ('data', 'next')
@tiggreen
tiggreen / Sqrt.scala
Created May 11, 2014 04:06
Calculating the Square Root of a given integer. Credits to the "Functional Programming Principles in Scala" course in Coursera.
def sqrt(x: Double) = {
def sqrtIter(guess: Double): Double =
if (isGoodEnough(guess)) guess
else sqrtIter(improve(guess))
def isGoodEnough(guess: Double) =
math.abs(guess * guess - x) / x < 0.001
def improve(guess: Double) =
@tiggreen
tiggreen / wordCount.scala
Last active August 29, 2015 14:01
Word count of a user specified text file. My first code in Scala. Learning.
/*
Reads a filename from user input and returns a Map which contains
the number of occurances of each word in the file.
Words are separated by space.
Scala rocks!
Author: Tigran Hakobyan
*/
@tiggreen
tiggreen / mergeAndquickSorts.py
Last active August 29, 2015 14:00
Merge and Quick sorts in Python
#Author @tigranhk
# mergeSort
def mergeSort ( lst ):
if not lst:
return lst
elif (len(lst) == 1):
return lst
else:
(half1, half2) = split (lst)
@tiggreen
tiggreen / makefile
Created April 22, 2014 17:40
Makefile sample.
CPC = /usr/bin/g++
CPFILES = tli.cpp Scanner.cpp ScannerException.cpp SymbolTable.cpp
HFILES = Scanner.h ScannerException.h SymbolTable.h
SOURCEFILES = $(HFILES) $(CPFILES)
OBJFILES = Scanner.o ScannerException.o SymbolTable.o
@tiggreen
tiggreen / UniqueChars.java
Created April 22, 2014 14:24
Checking if the string contains only unique chars.
public class UniqueChars {
//uses an additional data structure
public static boolean isUnique(String str) {
// if the string is in the ASCII format
Boolean[] arr = new Boolean[256];
for (int i = 0; i < arr.length; ++i) {
arr[i] = false;
}
//char[] charArray = str.toCharArray();