Skip to content

Instantly share code, notes, and snippets.

View TomColBee's full-sized avatar

Thomas Beeson TomColBee

View GitHub Profile
@TomColBee
TomColBee / SelectionSort.py
Created August 9, 2018 07:03
Selection Sort Algorithm
# selection sort
def selection_sort(n):
moves = 0
print("Unsorted list: {}".format(unsorted_list))
length_of_list = len(unsorted_list)
for i in range(0,length_of_list-1):
# get min of list [i .... length_of_list]
@TomColBee
TomColBee / BubbleSort.py
Created August 8, 2018 18:45
Bubble Sort Algorithm
# bubble sort
def bubble_sort(n):
moves = 0
print("Unsorted list: {}".format(unsorted_list))
length_of_list = len(unsorted_list)
print("Number of numbers : {}".format(length_of_list))
@TomColBee
TomColBee / DiamondLetterKata.py
Created August 8, 2018 18:44
Diamond Shaped Star Letters
def diamond_letters(n):
# convert string to upper case
n = n.upper()
# create letter string
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
# find given letter n in the letters string and return index+1
n = letters.find(n) + 1
@TomColBee
TomColBee / DiamondStarKata.py
Created August 8, 2018 18:43
Diamond Shaped Kata Stars
def diamond(n):
orig_n = int(n)
orig_n_2 = int(n)
# first line of star
spaces = int(n-1)
print(" " * spaces + "*")
# middle section
@TomColBee
TomColBee / IrisClassification.py
Created July 25, 2018 07:13
Machine Learning: Simple Classification using Iris dataset
# Machine learning example using iris dataset
# Classification problem.
# Uses a variety of different algorithms to predict class based on sepal/petal lengths and widths
# Python version 3.6
# Source: https://machinelearningmastery.com/machine-learning-in-python-step-by-step/
# Step 1: Check Python versions
# Step 2: Load libraries
# Step 3: Load dataset
@TomColBee
TomColBee / PentagonalNumber.py
Created July 16, 2018 19:27
Coderbyte Python Challenge: PentagonalNumber
# PentagonalNumber(num) reads num which will be a positive integer and determine how many dots exist in a pentagonal shape
# around a center dot on the Nth iteration.
# For example, in the image below you can see that on the first iteration there is only a single dot,
# on the second iteration there are 6 dots, on the third there are 16 dots, and on the fourth there are 31 dots.
# The formula for this sequence is (5(n-1)^2 + 5(n-1) + 2) / 2
def PentagonalNumber(num):
num = num - 1
@TomColBee
TomColBee / ChessboardTravelling.py
Created July 16, 2018 19:19
Coderbyte Python Challenge: ChessboardTravelling
# Function input is a string that are the coordinates of a space on a 8x8
# chess board. The structure of str will be (x y)(a b) where (x y) is the
# current position and (a b) is the new position.
# a and b will be strictly greater than x and y respectively.
# Program will determine the number of ways there are of travelling from
# (x y) to (a b) by only travelling up and right.
def ChessboardTraveling(str):
@TomColBee
TomColBee / KaprekarsConstant.py
Last active January 21, 2022 05:30
Coderbyte Python Challenge: KaprekarsConstant
# Using the Python language, have the function KaprekarsConstant(num) take
# the num parameter being passed which will be a 4-digit number with at least
# two distinct digits.
# Your program should perform the following routine on the number:
# Arrange the digits in descending order and in ascending order
# subtract the smaller number from the bigger number. Then repeat the previous step.
# Performing this routine will always cause you to reach a fixed number: 6174.
@TomColBee
TomColBee / SimpleSymbols.py
Created July 15, 2018 14:59
Coderbyte Python Challenge: Simple Symbols
# Have the function SimpleSymbols(str) take the str parameter being passed and
# determine if it is an acceptable sequence by either returning the string true or false.
# The str parameter will be composed of different symbols with several letters
# between them (ie. ++d+===+c++==a) and for the string to be true
# each letter must be surrounded by a + symbol.
# Examples:
# +t+a+b+ returns True
# +++a+s++++e+ returns True
@TomColBee
TomColBee / SimpleAdding.py
Created July 15, 2018 07:33
Coderbyte Python Challenge: SimpleAdding
# Have the function SimpleAdding(num) add up all the numbers from 1 to num.
# For example: if the input is 4 then your program should return 10 because 1 + 2 + 3 + 4 = 10.
def SimpleAdding(num):
sum = 0
for x in range(1,num+1):
sum = sum + x
return sum
print(SimpleAdding(input()))
# print SimpleAdding(raw_input())