What A Long, Strange Trip It’s Been

Posted in Personal on March 7th, 2010 by Cole – Comments

While I haven’t really played World of Warcraft in a few months, I did log on recently to finish those holiday achievements that I didn’t do last year.  After knocking out Love is in the Air and the Lunar Festival (with 30 minutes to spare), I finally finished that meta-meta-achievement What A Long Strange Trip It’s Been.

read more »

Song of the Day: Poison Cup

Posted in Syndicated on March 6th, 2010 by C. Gleason – Comments

“A sip or a spoonful won’t do.”

Song of the Day: Poison Cup
Artist: M. Ward
Album: Post-War

Listen here.

Why Numbering Should Start at Zero

Posted in Syndicated on March 3rd, 2010 by whackedspinach – Comments Off

When first learning how to use computer programming languages, something that often throws newcomers off is the way number ranges are used.  In most languages, 0 is always the first value, not 1.  Also, most range functions are non-inclusive on the endpoint number.  Well, E. W. Dijkstra has a good mathematical explanation for why numbering should start at zero, and I would encourage you to read it if you are interested in computer science and/or math.

Found Poetry

Posted in Uncategorized on March 2nd, 2010 by Cole – Comments

I was required to write a poem for English class today, a specific type of poetry called found poetry. Basically for found poetry, the author just takes lines from a source (headlines, road signs, song lyrics, etc) and makes them into a poem.  So here is my quick attempt at it using just of Montreal lyrics.

Poems of Montreal (Found Poetry)

My mind rejects the frequency
Still, I only feel alive when the VU is flashing
Try to find a way to spike the senses
It’s static craziness to me
You turn the dial, I’ll try and smile
Oh, I just never smiled

I felt the darkness of the black metal bands
The Greek chorus of my skull is choking on their dulcet tones
Alarms going off in my head
Rapture rapes the muses
And the void that’s left confuses

I was a landscape in your dream
You might forget them but your nightmares
they don’t forget about you
Look, the sky is peppered with sea birds

I was never young, even as a child
You know, I waved your flag, back when no one else did
Do you remember our last summer as independents?
I just want things to be the way they used to be
You keep me lit like antediluvian Troy

Project Euler Problems 1 – 5 in Python

Posted in Syndicated on March 1st, 2010 by C. Gleason – Comments Off

Lately, I have been messing around with Project Euler, a site with over 280 math problem designed to be solved using computer programming skills.  You’ve probably already seen rseaton’s solution for Problem 1 in C, but I prefer python for it’s easy to read syntax and simplicity.  I am not an experienced programmer by any definition, so many of my scripts will be inefficient and cumbersome.  If you have improvements for them, please post in the comments.

Warning: Spoilers!

Problem #1

“If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.”

Okay, so this is rather simple.  we’re going to make a list of all numbers from 0 to 1000.  Then we are going to take that list and pull out anything that is evenly divisible (no remainder) by either 3 or 5.  Finally we will find the sum of all the numbers in that list.

Here is my resulting python script:

#Create a list containing all numbers below 1000.
possibles = range(1000)
#Find all numbers in that list that are multiples of 3 or 5.
multiples = [x for x in possibles if (x % 3 == 0) or (x % 5 == 0)]
#Add all the multiples together.
total = sum(multiples)
#Print the resulting total.
print total

Pretty simple, eh?  If you didn’t understand line 4, check out list comprehension.

Problem #2

“Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

Find the sum of all the even-valued terms in the sequence which do not exceed four million.”

So our strategy here is this:

  1. Create a list containing the Fibonacci sequence up to 4 million.
  2. Pull all the numbers that are evenly divisible by 2.  We could do this with a modulus function, but I found a faster way.
  3. Sum the list to find the answer.

Here’s my code:

fibonacci = [] # create empty list to append to
a,b = 1,0 # assign initial values
while a < 4000000: #this loop will add numbers to our fibonacci list
    fibonacci.append(a)
    b, a = a, a+b # use multiple assignments to do these values
# Every 3rd number in the fibonacci sequence is even,
# so lets just pull all of those, starting with the third item (which is 2).
evens = fibonacci[2::3]
total = sum(evens) # add them up
print total

When we made the evens list, we used something called stride notation. The first value (2) tells the program to start at the 3rd item in Fibonacci. The second value (3) tells our program to take every 3rd item.  In the case of the Fibonacci sequence, all those are even.

Problem #3

“The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?”

This is one that I found to be kind of tricky.  I had to look up some various prime factorization algorithms and their python code equivalents.  You just need to use one of the algorithms to make a list of all prime factors.  Then select the largest one.  This is the final code:

def factor(n):
        if n == 1: return [1] # 1 is already prime.
        i = 2				   # i will be our divisor
        limit = n**0.5             #We only need to go up to the square root of our number.
        while i <= limit:
                if n % i == 0:     # Check if our number is divisible by the ever increasing i
                        ret = factor(n/i)
                        ret.append(i)
                        return ret
                i += 1
        return [n]
# Actual computation
print max(factor(600851475143))

Problem #4

“A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 x 99.

Find the largest palindrome made from the product of two 3-digit numbers.”

Ah, palindromes.  They’re kind of fun right? And really, that is probably the easiest part in this problem.  We check the value against itself with a stride notation of -1.  That tells the program to reverse the value.  The hard part is making sure that the palindrome you find is a product of two three digit numbers.  I know my way is not the most efficient (it take 11.53 sec to complete on my computer), but I’m not sure how I want to improve it at the moment.  Please leave me some help in the comments.

def checkPalindrome(x): # a simple function that reverses the string of x to check for a palindrome.
	if str(x) == str(x)[::-1]:
		return True
done = False #This will break us out of the for loop once a result is found.
for x in reversed(xrange(100**2,999**2)): #The palindrome will be in this range.
	if done: # If result is found, break loop.
		break
	elif checkPalindrome(x): # Check x to see if it is a palindrome.
		for fac1 in reversed(xrange(100,1000)): # Factors must be in this range.
			for fac2 in reversed(xrange(100,1000)):
				if x == (fac1 * fac2): #The palindrome has to be a product of the two factors
					result = x
					done = True # Tell the loop we're done.
print result

Problem #5

“2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest number that is evenly divisible by all of the numbers from 1 to 20?”

This is a fairly easy problem.  We just need to find the least common multiple (LCM) of all the number 1-20.  While python doesn’t contain a function to find lcm by default (like Ruby), we can make one.  The LCM of two numbers actually equals their product divided by their GCD (Greatest Common Divisor).  To find the GCD, we will use Euclid’s Algorithm.  Here is the code:

def euclid(a,b): # We're going to use Euclid's algorithim to determine the GCD of the numbers.
	while b > 0:
		remainder = a % b
		a, b = b, remainder
	return a
 
def lcm(a,b):  #Now find the LCM using the previous GCD.
	return a*b / euclid(a,b)
print reduce(lcm, range(1,21)) # Now perform the LCM function over the range of numbers.

That reduce function at the end just makes the function repeat for all numbers 1-20, since the function can only handle 2 at a time.

Hopefully I will be able to make my way through the next 5 problems and share my solutions with you.  stay tuned!

Related Posts

Project Euler 1 – 5 in Ruby
Euler Solution for Problem 1 in C++

Limor Fried: Open Source Engineer

Posted in Syndicated on February 27th, 2010 by C. Gleason – Comments Off

x0xb0x: Synth created by Adafruit

Lifehacker has an interesting post up about Limor Fried, an engineer who produces various ’social defense’ mechanisms.  Some of her projects include a portable wireless signal jammer, a universal TV zapper, and a game console.  I believe she releases all the schematics for her projects under open source licenses, and also sells kits at her own company, Adafruit.  After seeing the interesting cell phone jammer and non-lethal weapon she created, I looked into some of her other projects and realized she was the inventor of the MintyMP3 and MintyBoost (which I have actually tried).

Head on over to Lifehacker to read the full post about her, or visit her site.

Ubuntu 10.04 Will Have a Music Store

Posted in Syndicated on February 23rd, 2010 by C. Gleason – Comments Off

It seems Ubuntu is going to throw its very own music store into the mix with the upcoming release of Ubuntu 10.04 Lucid Lynx later this spring. Lifehacker reports that you will be able to download a song up to three times after you’ve purchased it, and the songs will be DRM free. Unfortunately, 7Digital (the music provider) only seems to offer downloads up to 320k MP3s.  While not a bad quality, FLAC would be a much more preferable choice, especially since Ubuntu doesn’t ship with an MP3 codec by default.

Expect to see the store pop up in Rhythmbox (and Banshee?) in Lucid Lynx Alpha 3.

[via Lifehacker]

Twitter’s Exponential Growth Rate

Posted in Syndicated on February 22nd, 2010 by C. Gleason – Comments Off

Twitter has grown pretty large in just 4 years, and now the Twitter analytics team has released the graphs to visualize it.  The following graph shows the amount of Tweets per Day.

Click to enlarge.

“Folks were tweeting 5,000 times a day in 2007. By 2008, that number was 300,000, and by 2009 it had grown to 2.5 million per day. Tweets grew 1,400% last year to 35 million per day. Today, we are seeing 50 million tweets per day—that’s an average of 600 tweets per second. (Yes, we have TPS reports.)”

I want to see the same information overlaid with dates that celebrities, such as Oprah,  joined .

[via Twitter Blog]

Google Weather Fetcher

Posted in Syndicated on February 7th, 2010 by Cole – Comments

I’ve been messing around with python lately, since I want to learn a programming language. This weekend I decided to sit down and write a script, so after much deliberation I wrote one that pulls weather data from Google’s weather API and displays it in the console.   I know it probably isn’t correct form, but it works. If you want to check it out, download it below.  I want to store it on the server anyways.

Python source code: Google_Weather_Fetcher_script.zip
Windows executable: Google_Weather_Fetcher_exe.zip

iPad Predictions: Reflection

Posted in Opinion/Analysis on January 29th, 2010 by Cole – Comments

apple ipad

I read the Engadet liveblog earlier today and saw the Apple iPad at the announcement earlier today. I have to say, I have some mixed feelings regarding this product.

I’m going to go ahead and compare my earlier predictions to the actual device, and see how I matched up after the break.

read more »