Skip to content

Instantly share code, notes, and snippets.

View mauriciogardini's full-sized avatar

Maurício Gardini mauriciogardini

View GitHub Profile
@mauriciogardini
mauriciogardini / shell_sort.py
Last active November 8, 2019 02:01
Shell Sort implementation in Python
from math import ceil
def _return_list_gaps(size, ratio=None):
gaps = list()
if not ratio:
ratio = 2.2
while size > 1:
size = ceil(size / ratio)
gaps.append(size)
@mauriciogardini
mauriciogardini / selection_sort_optimized.py
Created November 1, 2019 01:23
Selection Sort optimized implementation in Python
def selection_sort_optimized(array, decrescent=False):
if len(array) <= 1:
return array
for x in range(len(array)):
left_swap_index = x
right_swap_index = x
for y in range(x + 1, len(array) - x):
if ((decrescent and array[y] > array[left_swap_index]) or
(not decrescent and array[y] < array[left_swap_index])):
left_swap_index = y
@mauriciogardini
mauriciogardini / selection_sort.py
Created November 1, 2019 01:20
Selection Sort implementation in Python
def selection_sort(array, decrescent=False):
if len(array) <= 1:
return array
for x in range(len(array)):
swap_index = x
for y in range(x + 1, len(array)):
if ((decrescent and array[y] > array[swap_index]) or
(not decrescent and array[y] < array[swap_index])):
swap_index = y
array[x], array[swap_index] = array[swap_index], array[x]
@mauriciogardini
mauriciogardini / insertion_sort_optimized.py
Created October 1, 2019 21:12
Insertion Sort optimized implementation in Python
def insertion_sort_optimized(array, decrescent=False):
if len(array) <= 1:
return array
for x in range(1, len(array)):
current = array[x]
y = x - 1
while y >= 0 and ((decrescent and current > array[y]) or
(not decrescent and current < array[y])):
array[y + 1] = array[y]
y = y - 1
@mauriciogardini
mauriciogardini / insertion_sort.py
Created October 1, 2019 21:10
Insertion Sort implementation in Python
def insertion_sort(array, decrescent=False):
if len(array) <= 1:
return array
for x in range(1, len(array)):
y = x
while y > 0 and ((decrescent and array[y] > array[y - 1]) or
(not decrescent and array[y] < array[y - 1])):
array[y], array[y - 1] = array[y - 1], array[y]
y = y - 1
return array
@mauriciogardini
mauriciogardini / bubble_sort_optimized.py
Last active October 1, 2019 21:12
Bubble Sort optimized implementation in Python
def bubble_sort_optimized(array, decrescent=False):
if len(array) <= 1:
return array
for x in range(len(array) - 1):
swapped = False
for y in range(len(array) - x - 1):
if ((decrescent and array[y] < array[y + 1]) or
(not decrescent and array[y] > array[y + 1])):
array[y], array[y + 1] = array[y + 1], array[y]
swapped = True
@mauriciogardini
mauriciogardini / bubble_sort.py
Created August 15, 2019 03:17
Bubble Sort implementation in Python
def bubble_sort(array, decrescent=False):
if len(array) <= 1:
return array
for x in range(len(array) - 1):
for y in range(len(array) - x - 1):
if ((decrescent and array[y] < array[y + 1]) or
(not decrescent and array[y] > array[y + 1])):
array[y], array[y + 1] = array[y + 1], array[y]
return array
@mauriciogardini
mauriciogardini / slate-source
Created February 17, 2013 18:36
Slate dotfile - Source section
# Source's directive: source filename optional:if_exists
source ~/.slate-other-configurations if_exists
@mauriciogardini
mauriciogardini / slate-bind
Last active December 13, 2015 20:48
Slate dotfile - Bind section
# Bind's directives: bind key:modifiers operation parameter+
bind key:modal-key operation parameter+
# Location - Sets the window to the specified location.
bind return:shift;cmd ${full}
bind k:shift;cmd ${tophalf}
bind j:shift;cmd ${bottomhalf}
bind h:shift;cmd ${lefthalf}
bind h:shift;alt;cmd ${leftthird}
bind i:shift;alt;cmd ${middlethird}
@mauriciogardini
mauriciogardini / slate-default
Last active December 13, 2015 20:48
Slate dotfile - Default section
# Default's directive: default layout-or-snapshot-name screen-configuration
# Triggers the twoScreenLayout when there are 2 monitors.
default twoScreenLayout count:2