This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def diamond(n): | |
orig_n = int(n) | |
orig_n_2 = int(n) | |
# first line of star | |
spaces = int(n-1) | |
print(" " * spaces + "*") | |
# middle section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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()) |
NewerOlder