Skip to content

Instantly share code, notes, and snippets.

@Caleb2501
Caleb2501 / Challenge31.py
Created July 13, 2013 21:24
Yay challenge 31 completed! This one was a lot of fun. I liked the way my code turned out too. I think it looks quite clean, and I used functions that call other functions. Pretty nifty.
# 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'}
@Caleb2501
Caleb2501 / challenge30.py
Created July 7, 2013 23:50
This one wasn't too hard got it to do the correct thing on the first run! woot!
# 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:
@Caleb2501
Caleb2501 / Martin.txt
Last active December 19, 2015 10:38
Yay another challenge down! I had no idea that Demetri Martin had made this poem! pretty impressive.
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.
@Caleb2501
Caleb2501 / Challenge28.py
Created July 6, 2013 20:12
I completed this challenge 28, but the code takes way too long to process with a range of a million digits from 1 to a million. If you limit either the amount of digits or the range pool then it runs quickly enough. fun times!
# 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 = []
@Caleb2501
Caleb2501 / Challenge2.java
Created May 19, 2013 00:11
This is my second effort in Java. I modified my original Python program to function in Java. I think t turned out pretty well. The process allowed me to write the code without having to think too hard about what exactly I was making and how I could make it calculate correctly . I will probably do the same with most of the other challenges.
// 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;
@Caleb2501
Caleb2501 / Challenge25.py
Created May 17, 2013 04:10
This challenge 25 was a lot of fun. I added some additional statistics to the end of the output to make it interesting.
# 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.
@Caleb2501
Caleb2501 / challenge24.py
Last active December 17, 2015 09:39
This one is an intermediate challenge. I had to have quite a bit of help on it. I also had to crte a break line that resets the fraction to 3/1 because it kept freezing up on me. well it is finished anyway. I also figured out that in order to get a float from two ints you have to divide them as floats. makes sense in hind sight.
#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)
@Caleb2501
Caleb2501 / Challenge1.java
Created May 12, 2013 19:12
First Reddit coding challenge completed in Java! exciting! Got the basics through an Udemy course, liking it so far.
// 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;
@Caleb2501
Caleb2501 / challenge23.py
Created May 5, 2013 21:54
In this challenge I sent one value to the function and returned two using the multi-assign ability in Python I was able to assign them to new variables. That was pretty sweet.
# 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]
@Caleb2501
Caleb2501 / challenge22.py
Created May 5, 2013 21:21
This one was too easy. Although, I am kind of glad after that last one!
#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