Skip to content

Instantly share code, notes, and snippets.

View KoderDojo's full-sized avatar

David Hayden KoderDojo

View GitHub Profile
@KoderDojo
KoderDojo / caesar-cipher.py
Created June 26, 2016 00:33
Caesar Cipher Using Python
def encrypt(letter, key):
# must be single alphabetic character
if not letter.isalpha() or len(letter) != 1:
return letter
# convert to lowercase
letter = letter.lower()
# convert to numerical value 0 - 25
@KoderDojo
KoderDojo / insertion-sort.py
Created June 25, 2016 19:10
Insertion Sort Using Python
import random
def InsertionSort(lst):
print 'List {}'.format(lst)
length = len(lst)
for i in range(1, length):
value = lst[i]
j = i - 1
@KoderDojo
KoderDojo / bubble-sort.py
Created June 24, 2016 18:41
Bubble Sort Using Python
import random
def BubbleSort(numbers):
swapped = True
maxIndex = len(numbers) - 1
while swapped:
swapped = False
for i in range(maxIndex):
@KoderDojo
KoderDojo / bisection-method.py
Created June 22, 2016 22:32
Bisection Method of Calculating Square Roots Using Python
number = abs(float(raw_input("Calculate square root of? ")))
lowerBound = abs(float(raw_input("Lower bound value? ")))
upperBound = abs(float(raw_input("Upper bound value? ")))
epsilon = 0.001
while True:
guess = (lowerBound + upperBound) / 2
difference = guess**2 - number
if abs(difference) <= epsilon:
@KoderDojo
KoderDojo / babylonian.py
Last active June 22, 2016 17:56
Babylonian Method of Calculating Square Roots Using Python
number = abs(float(raw_input("Calculate square root of? ")))
guess = abs(float(raw_input("Initial guess? ")))
epsilon = 0.001
while True:
difference = guess**2 - number
print('{} : {}'.format(round(guess, 4), round(difference, 4)))
if abs(difference) <= epsilon:
break