Skip to content

Instantly share code, notes, and snippets.

View robbie01's full-sized avatar
🗿
bruh

Robbie robbie01

🗿
bruh
View GitHub Profile
@robbie01
robbie01 / mergesort.py
Last active December 30, 2016 02:28
Merge sort implemented in Python 3
def mergesort(c):
if len(c) > 1:
pivot = len(c)//2
a = c[:pivot]
b = c[pivot:]
mergesort(a)
mergesort(b)
ap = 0
bp = 0
cp = 0
@robbie01
robbie01 / bubblesort.py
Last active January 1, 2017 01:03
Bubble sort implemented in Python 3
def bubblesort(list):
swapped = True
while swapped:
swapped = False
for p in range(len(list)-1):
if list[p] > list[p+1]:
list[p] = list[p] ^ list[p+1]
list[p+1] = list[p] ^ list[p+1]
list[p] = list[p] ^ list[p+1]
swapped = True
@robbie01
robbie01 / quicksort.py
Created December 30, 2016 05:41
Quicksort implemented in Python 3
from random import randrange
def qsort(list):
if len(list) > 1:
pivot = list.pop(randrange(0, len(list)))
a = qsort([i for i in list if i < pivot])
b = qsort([i for i in list if i >= pivot])
return a + [pivot] + b
else:
return list
@robbie01
robbie01 / selectionsort.py
Last active December 31, 2016 04:43
Selection sort implemented in Python 3
def selectionsort(list):
n = []
while len(list) > 1:
n.append(list.pop(list.index(min(list))))
return n
if __name__ == '__main__':
from sys import argv
from random import shuffle
@robbie01
robbie01 / timsort.py
Created December 30, 2016 05:44
Timsort implemented in Python 3
if __name__ == '__main__':
from sys import argv
from random import shuffle
list = list(range(int(argv[1])))
list.sort() # ;)
print(all(list[i] <= list[i+1] for i in range(len(list)-1)))
# seriously though timsort is really weird
@robbie01
robbie01 / heapsort.py
Last active December 31, 2016 23:31
Heap sort implemented in Python 3
from heapq import heapify, heappop #is this cheating?
def heapsort(list):
heap = heapify(list)
newList = []
while heap:
newList.append(heappop(heap))
return newList
if __name__ == '__main__':
from sys import argv
@robbie01
robbie01 / shellsort.py
Last active December 30, 2016 23:09
Shellsort implemented in Python 3 using various gap sequences
from math import floor
def shellsort(list):
gaps = gengaps(len(list))
for gap in gaps:
for i in range(gap, len(list)):
temp = list[i]
j = i
while j >= gap and list[j-gap] > temp:
list[j] = list[j - gap]
@robbie01
robbie01 / lsdradixsort.py
Last active January 7, 2017 22:03
LSD Radix sort implemented in Python 3 using base 10 (but can be easily modified to use any base)
base = 10
def radixsort(list):
maxPlace = max(len(int2base(i, base)) for i in list)
list = [(0, i) for i in list]
for i in range(1, maxPlace + 1):
list = [(FindInPlace(j, base, i), j) for _, j in list]
newList = []
for j in range(base):
newList += [k for k in list if k[0] == j]
@robbie01
robbie01 / reload.js
Last active March 30, 2017 19:44
Reload the page without reloading the page (uses Fetch API and ES6)
fetch(window.location.href).then(res =>
res.text().then(text => {
let domParser = new DOMParser()
let newDoc = domParser.parseFromString(text, res.headers.get('Content-Type').split(';')[0])
let newNode = document.importNode(newDoc.documentElement, true)
document.replaceChild(newNode, document.documentElement)
})
)
@robbie01
robbie01 / emojify.js
Created April 5, 2017 01:04
Convert text into emojis
/*
emojify.js 1.0.0
by robbie0630
Description:
converts text into Discord-compatible emojis
PLANNED FEATURES:
* needs more ES2015
* needs more ES2016