Skip to content

Instantly share code, notes, and snippets.

View AaronFlower's full-sized avatar
💭
I may be slow to respond.

AaronFlower

💭
I may be slow to respond.
View GitHub Profile
@AaronFlower
AaronFlower / quick-sort.hs
Created October 31, 2017 03:18
quick sort haskell version
quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) =
let smallerSorted = quicksort [a | a <- xs, a <= x]
biggerSorted = quicksort [a | a <- xs, a > x]
in smallerSorted ++ [x] ++ biggerSorted
@AaronFlower
AaronFlower / insertion-sort.py
Created October 27, 2017 02:25
insertion-sort python.
def insertion_sort(data):
length = len(data)
for i in range(1, length):
j = i
while j > 0 and data[j] < data[j-1]:
tmp = data[j-1]
data[j - 1] = data[j]
data[j] = tmp
j -= 1
@AaronFlower
AaronFlower / vector-rotation.py
Last active October 26, 2017 02:34
Programming Pearls: Column 2, vector-rotation
def vector_rotation(str, pos):
'''Transpose concept: (A.T B.T).T = (BA) '''
l_half = str[:pos][::-1]
r_half = str[pos:][::-1]
new_str = l_half + r_half
return new_str[::-1]
s = 'abcdefgh'
print(vector_rotation(s, 2))
print(vector_rotation(s, 3))
@AaronFlower
AaronFlower / binary-search.js
Last active October 26, 2017 02:23
Binary Search
a = Array.from({length: 15}).map((_,i) => i)
function binarySearch(arr, needle)
{
let begin = 0, end = arr.length - 1
while (begin <= end) {
let mid = Math.floor((end - begin) / 2) + begin
if (arr[mid] === needle) {
return mid
} else if (arr[mid] > needle) {
@AaronFlower
AaronFlower / insertion-sort.js
Last active October 27, 2017 02:26
Insertion sort javascript version
function insertionSort(data)
{
for(let i = 1; i < data.length; ++i) {
let j = i
while(j > 0 && data[j] < data[j - 1]) {
let tmp = data[j]
data[j] = data[j - 1]
data[j - 1] = tmp
j --
}