Skip to content

Instantly share code, notes, and snippets.

@Caleb2501
Caleb2501 / Challenge21.py
Created May 5, 2013 18:31
This one was very difficult for me. Mostly because I was going about it in the entirely wrong way. I had to look up someone elsees answer, and then modify it for error checking. Thanks Jnaranjo!
# Input: a number
# Output : the next higher number that uses the same set of digits.
from itertools import permutations
def nextHighest(num):
"""This function takes a number as a string, finds all permutations of that number,
and then returns the next highest value using those digits."""
if len(num) == 1:
return num+num
normal = []
@Caleb2501
Caleb2501 / challenge20.py
Created April 24, 2013 03:40
This one was quite easy, but it took a bit of mulling over before I was sure it would be correct..
#create a program that will find all prime numbers below 2000
primeNumbers = []
for num in range(1, 2000):
x = num
count = 0
while x > 0:
if num %x == 0:
count += 1
x -= 1
@Caleb2501
Caleb2501 / SherCount.py
Last active December 16, 2015 11:58
There are two chapter headings II and III that this program counts when it shouldn't, but other than that it successfully WINS!
#Write a program that counts the number of alphanumeric characters there are in The
# Adventures of Sherlock Holmes. Exclude the Project Gutenberg header and footer, book
# title, story titles, and chapters. Post your code and the alphanumeric character count.
loop = True
charCount = 0
numCount = 0
# Creating reference lists for characters to count.
charList = 'abcdefghijklmnopqrstuvwxyxABCDEFGHIJKLMNOPQRSTUVWXYZ'
numList = '1234567890'
# Creating start and end strings to keep the meat of the file that we will be counting
@Caleb2501
Caleb2501 / challenge18.py
Created April 11, 2013 02:32
This took a lot of thinking, but the for loop turned out to be something very simple! Awesome!
#Often times in commercials, phone numbers contain letters so that they're easy to
# remember (e.g. 1-800-VERIZON). Write a program that will convert a phone number that
# contains letters into a phone number with only numbers and the appropriate dash. Click
# here to learn more about the telephone keypad.
print "This program will convert numbers with letters into the digits they represent."
phone = raw_input("Please enter a 1-800 number: ")
phone = phone.upper()
converter = {'A':'2', 'B':'2', 'C':'2', 'D':'3', 'E':'3', 'F':'3',
'G':'4', 'H':'4', 'I':'4', 'J':'5', 'K':'5', 'L':'5',
'M':'6', 'N':'6','O':'6', 'P':'7', 'Q':'7', 'R':'7',
@Caleb2501
Caleb2501 / Challenge17.py
Created April 11, 2013 00:45
Practicing some error catching, but I think it makes too many if statemnts.
#Write an application which will print a triangle of stars of user-specified height, with each line having
#twice as many stars as the last.
def triangler(char, height):
"""assumes that char is a single character, and height is an integer between 1 - 10.
Uses the height int to build a triangle on the screen."""
upChar = ""
for c in range(0, height):
upChar = upChar + char
char = upChar
@Caleb2501
Caleb2501 / challenge16.py
Created March 30, 2013 00:18
Daily Programmer challenge #16 In which I use a function of my own design.
# coding=utf-8
# Write a function that takes two strings and removes from the first string any
# character that appears in the second string. For instance, if the first string is “Daily Programmer”
# and the second string is “aeiou ” the result is “DlyPrgrmmr”.
# note: the second string has [space] so the space between "Daily Programmer" is removed
def newString(str1, str2):
"""Takes two strings and returns a new string with letters of the first removed from the second"""
result = []
for i in str1:
@Caleb2501
Caleb2501 / RLjustify.py
Created March 28, 2013 02:09
Daily programmer challenge #15
#write a program to right, or left justify text in a file.
start = False
f = open('chuckles.txt', 'r+')
test = f.readlines() #creating a copy of the file for looping while modifying the original file.
for line in test:
scoop = line.rjust(50)
if not start: # puts block at the top of the file to overwrite the existing text
f.seek(0)
start = True
f.writelines(scoop)
@Caleb2501
Caleb2501 / daycalc.py
Created March 17, 2013 01:06
Daily programing challenge number 12!
#find the number of the year for the given date. For example, January 1st
#would be 1, and december 31st is 365
import datetime
loop = True
print "We are going to figure out what day number you chose based on the date you input."
while loop:
year = input('Enter a year (YYYY): ')
month = input('Enter a month (MM): ')
@Caleb2501
Caleb2501 / birthday.py
Created March 7, 2013 02:25
Birthday AWESOME! Reddit challenge 11.
import datetime
Days = ['Monday', 'Tuesday', 'Wedneday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
loop = True
print "Welcome to the magical emporium of fun!"
print "Give me your birth date, and I will tell you what day of the week you were born on."
while loop:
year = input('Enter your birth year (YYYY): ')
month = input('Enter your birth month (MM): ')
@Caleb2501
Caleb2501 / challenge10.py
Created January 27, 2013 23:58
challenge 10! This is the last one I will be doing for now.
#The exercise today asks you to validate a telephone number, as if written on an input form. Telephone numbers can be written as ten digits, or with dashes, spaces, or dots between the three segments, or with the area code parenthesized; both the area code and any white space between segments are optional.
#Thus, all of the following are valid telephone numbers: 1234567890, 123-456-7890, 123.456.7890, (123)456-7890, (123) 456-7890 (note the white space following the area code), and 456-7890.
#The following are not valid telephone numbers: 123-45-6789, 123:4567890, and 123/456-7890.
import re
phoneNum = raw_input("Please enter a phone number: ")
matchObj = re.match( r'^([1]?)([\(\/\. ]?)[2-9][\d]{2}([\.\- \)]?)[2-9][\d][\d][/\.\- ]?[\d]{4}$', phoneNum)
if matchObj:
print "Great! you gave me a good phone number: %s" % phoneNum
else:
print "You should try again that phone number sucked!"