Skip to content

Commit

Permalink
Projects Complete: 26
Browse files Browse the repository at this point in the history
Current Project: None
Latest Project: Text/CryptoCiphers.py

--Implemented Algorithms/bogosort.py because it was silly
--Implemented Algorithms/radixsort.py for fun
--Modified the general commenting of the files.
  • Loading branch information
jacobsky committed Aug 6, 2013
1 parent 680726f commit 0df40b8
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 26 deletions.
16 changes: 8 additions & 8 deletions Algorithms/binarychop.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ def chop(numToFind, arrayToSearch = [], offset = 0):
upperBound = len(arrayToSearch)
if(int(upperBound) > int(lowerBound+1)):
index = (lowerBound+upperBound)/2
print lowerBound, upperBound, index
print(lowerBound + " " + upperBound + " " + index)
else:
return -1
if(int(numToFind) == int(arrayToSearch[index])):
print "FINAL CHOP!"
print("FINAL CHOP!")
return index+offset
elif(int(numToFind) > int(arrayToSearch[index])):
print "HIGH CHOP!"
print("HIGH CHOP!")
return chop(numToFind, arrayToSearch[index:], index+offset)
elif(int(numToFind) < int(arrayToSearch[index])):
print "LOW CHOP!"
print("LOW CHOP!")
return chop(numToFind, arrayToSearch[:index], offset)
else:
return -1

print "Starting katachop!"
print "KATACHOP ", number, " FROM ", array, "!"
print("Starting katachop!")
print("KATACHOP " + number + " FROM " + array + "!")
index = chop(number, array, 0)
if(index < 0):
print "Index does not exist, shishou!"
print( "Index does not exist, shishou!")
else:
print "Here is your index, shishou! ", index
print( "Here is your index, shishou! " + index)
36 changes: 36 additions & 0 deletions Algorithms/bogosort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from sys import argv
import argparse
import random
array = argv[1]
array = array.split(",")
array = [int(l) for l in array]

def isSorted(array = []):
n = 1
while( n < len(array)-1 ):
if( array[n] < array[n-1] ):
return False
n = n + 1
return True

def shuffle(array = []):
temp = 0
rand = 0
for i in range( len(array) ):
temp = array[i]
rand = int( random.random() * ( len(array)-1 ) )
array[i] = array[rand]
array[rand] = temp
return array

def bogosort(array = []):
while(not isSorted(array)):
array = shuffle(array)
print("Shuffle!" + str(array) )
return array

print("Acquired array: " + str(array) )
print("Bogo sort activate!")
array = bogosort(array)
print("Bogo sort complete!")
print(array)
8 changes: 4 additions & 4 deletions Algorithms/bubblesort.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ def superiorbubblesort(array = []):
index += 1
print array
return array
print "Acquired array:", array
print "Bubble sort activate!"
print( "Acquired array: " + array )
print( "Bubble sort activate!" )
array = superiorbubblesort(array)
print "Bubble sort complete!"
print array
print( "Bubble sort complete!" )
print( array )
10 changes: 5 additions & 5 deletions Algorithms/mergesort.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ def mergesort(array = []):
right = array[midpoint:]
left = mergesort(left)
right = mergesort(right)
print left, right
#print left, right
return merge(left, right)

print "Acquired array:", array
print "Merge sort activate!"
print("Acquired array:" + array)
print("Merge sort activate!")
array = mergesort(array)
print "Merge sort complete!"
print array
print("Merge sort complete!")
print(array)
10 changes: 5 additions & 5 deletions Algorithms/quicksort.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ def quicksort(array = []):
else:
greater.append(array[i])
# print less, " ", pivotValue, " ", greater
return (quicksort(less) + [pivotValue] + quicksort(greater))
#return (quicksort(less) + [pivotValue] + quicksort(greater))

print "Acquired array:", array
print "Quick sort activate!"
print("Acquired array: " + str(array) )
print("Quick sort activate!" )
array = quicksort(array)
print "Quick sort complete!"
print array
print( "Quick sort complete!" )
print( array )
43 changes: 43 additions & 0 deletions Algorithms/radixsort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from sys import argv
import argparse
from collections import deque
import math
array = argv[1]
#base = int(argv[2])
array = array.split(",")
array = [int(l) for l in array]

def radixsort(array, base = 10):
# Check if the array is sorted
# Create 10 queues, one for each digit.
queueList = []
for i in range(10):
queueList.append(deque())

# Find the largest number in the list.
highestNumber = max( abs(num) for num in array )
#Acquire the total number of passes in the algorithm (1 for each digit)
totalPasses = int(math.log(highestNumber, base) + 1)
for digitNum in range(totalPasses):
#print(digitNum)
print(array)
for num in array:
index = str(num).zfill(digitNum + 1)
index = index[::-1]
#print("Value: " + str(index) + " Digit: " + str(digitNum) + " index[digit]:" + str(index[digitNum]) )
#print(digitNum)
#print(index[digitNum])
queueList[int(index[digitNum])].appendleft(num)
#print(str(queueList))
array = []
for q in queueList:
while(len(q) > 0):
array.append(q.pop())

# Return the sorted array
return array
print("Acquired array: " + str(array))
print("Radix sort activate!")
array = radixsort(array)
print("Radix sort complete!")
print(array)
3 changes: 2 additions & 1 deletion Graphics and Multimedia/ScreenSaver.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# Make a screensaver program that will run while your computer sits idle.
#To make a simple one use some standard pictures and then for added complexity try a 3D object that spins around the screen and bounces off the sides.
# To make a simple one use some standard pictures and then for added complexity
# try a 3D object that spins around the screen and bounces off the sides.
4 changes: 3 additions & 1 deletion Graphics and Multimedia/SignatureMaker.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# Ever seen those web board posts where someone has a generated signature made up? See if you can make a program that allows the user to specify a background, text, colors and alignment to make their own signatures or userbars.
# Ever seen those web board posts where someone has a generated signature made up?
# See if you can make a program that allows the user to specify a background, text,
# colors and alignment to make their own signatures or userbars.
10 changes: 9 additions & 1 deletion Networking/SiteCheckerwithTimeScheduling.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
# An application that attempts to connect to a website or server every so many minutes or a given time and check if it is up.
#If it is down, it will notify you by email or by posting a notice on screen.
# If it is down, it will notify you by email or by posting a notice on screen.

import sys


if __name__ == '__main__':
while(True):
print("Checking site")

3 changes: 2 additions & 1 deletion Networking/WebBot.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# An automated program which carries out tasks on the web including checking websites, page scraping, and summarization of data or web posting.
# An automated program which carries out tasks on the web including checking
# websites, page scraping, and summarization of data or web posting.

0 comments on commit 0df40b8

Please sign in to comment.