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
#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 |
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
#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 |
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
#Author: @tiggreen | |
class LinkedList(): | |
__slots__ = ('head', 'size') | |
class Empty(): | |
__slots__= () | |
class NonEmpty(): | |
__slots__= ('data', 'next') |
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 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) = |
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
/* | |
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 | |
*/ |
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
#Author @tigranhk | |
# mergeSort | |
def mergeSort ( lst ): | |
if not lst: | |
return lst | |
elif (len(lst) == 1): | |
return lst | |
else: | |
(half1, half2) = split (lst) |
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
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 |
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
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(); |
NewerOlder