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
# Write a function that takes two base-26 numbers in which digits are represented by letters with | |
# A=0, B=1, Z=25 and returns their product using the same notation. As an example, CSGHJ x CBA = FNEUZJA. | |
# Your task is to write the base-26 multiplication function. | |
base26 = {'A':0, 'B':1, 'C':2, 'D':3, 'E':4, 'F':5, 'G':6, 'H':7, 'I':8, 'J':9, 'K':10, 'L':11, 'M':12, | |
'N':13, 'O':14, 'P':15, 'Q':16, 'R':17, 'S':18, 'T':19, 'U':20, 'V':21, 'W':22, 'X':23, 'Y':24, 'Z':25} | |
base26rev = {0:'A', 1:'B', 2:'C', 3:'D', 4:'E', 5:'F', 6:'G', 7:'H', 8:'I', 9:'J', 10:'K', 11:'L', 12:'M', | |
13:'N', 14:'O', 15:'P', 16:'Q', 17:'R', 18:'S', 19:'T', 20:'U', 21:'V', 22:'W', 23:'X', 24:'Y', 25:'Z'} |
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
# Write a program that takes a list of integers and a target number and determines if any two integers | |
# in the list sum to the target number. If so, return the two numbers. | |
# If not, return an indication that no such integers exist. | |
numList = [] | |
def checkSum(numbers, sum): | |
for num in numbers: | |
for pNum in numbers: | |
if num + pNum == sum: |
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
Dammit I’m mad. | |
Evil is a deed as I live. | |
God, am I reviled? I rise, my bed on a sun, I melt. | |
To be not one man emanating is sad. I piss. | |
Alas, it is so late. Who stops to help? | |
Man, it is hot. I’m in it. I tell. | |
I am not a devil. I level “Mad Dog”. | |
Ah, say burning is, as a deified gulp, | |
In my halo of a mired rum tin. | |
I erase many men. Oh, to be man, a sin. |
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
# The array duplicates problem is when one integer is in an array for more than once. | |
# If you are given an array with integers between 1 and 1,000,000 or in some other interval | |
# and one integer is in the array twice. How can you determine which one? | |
import random | |
print "Creating a list of random numbers from 1 to 1,000,000." | |
numSet = [] | |
for i in range(1, 1000000): | |
numSet.append(random.randint(1, 100)) | |
checkList = [] |
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
// Create a calculator application that has use in your life. | |
// It might be an interest calculator, or it might be something | |
// that you can use in the classroom. | |
// I created this originally in Python, and this is a conversion to Java. | |
import java.util.Scanner; | |
public class Challenge2{ | |
public static void main(String[] agrs){ | |
int milesPerGallon, miles; | |
float gasPrice, mileCost; |
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
# In an election, the person with the majority of the votes is the winner. Sometimes | |
# due to similar number of votes, there are no winners. | |
# Your challenge is to write a program that determines the winner of a vote, | |
# or shows that there are no winners due to a lack of majority. | |
import random | |
def vote(team1, team2, times): | |
"""Takes two strings and an int, randomly votes for each of the strings | |
then gives the string that gained the most votes. |
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
#Happy (Be-Lated) Pi Day! To celebrate, write a program that calculates | |
#a list of rational approximations of Pi. Output should look like: | |
#3/1, 22/7, 333/106, 355/113, 52163/16604, 103993/33102, ... | |
import math | |
piLen = 0 | |
def examineFract(num): | |
"""takes a float value in the form of a string and an int value for the | |
number of digits that pi should be displayed at.""" | |
loop=True | |
num = float(num) |
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
// create a program that will ask the users name, age, and reddit username. | |
// have it tell them the information back, in the format: | |
// your name is (blank), you are (blank) years old, | |
// and your username is (blank) | |
import java.util.Scanner; | |
public class Challenge1{ | |
public static void main(String[] args){ | |
String name, username; |
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
# Input: a list | |
# Output: Return the two halves as different lists. | |
# If the input list has an odd number, the middle item can go to any of the list. | |
# Your task is to write the function that splits a list in two halves. | |
fullList = ['1', '2', '3', '4', 'alpha', 'beta', 'triangle', 'soup', 'pickle'] | |
def listSplitter(fullList): | |
""" This function takes 1 list value, and returns 2 lists of the original split in half.""" | |
listSize = len(fullList) | |
if listSize%2 == 0: | |
firstList = fullList[:listSize/2] |
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
#Write a program that will compare two lists, | |
# and append any elements in the second list that doesn't exist in the first. | |
# this was ridiculously easy. | |
list1 = ['caw', 'tweet', 'chirp', 'quack'] | |
list2 = ['tweet', 'chirp', 'hoo', 'cheep'] | |
for s in list1: | |
if s not in list2: | |
list2.append(s) | |
print "Here is a full list of bird calls that I know:" | |
print list2 |
NewerOlder