Friday, November 5, 2010

OCW Problem Set 1

These are my solutions from the second set of assignments in my OpenCourseWare study.

ps1a.py
#lists prime numbers up to the 1000th prime

def testPrime(x):
    factor = 2
    while factor**2 <= x:
        if x % factor == 0:
            return False
        else:
            factor = factor + 1
    
    return True

candidate = 3
numPrime = 1

while numPrime < 1000:
    if testPrime(candidate):
        numPrime = numPrime + 1
    candidate = candidate + 2

print "The 1000th prime number is", candidate - 2

ps1b.py
#asks for an upper limit
#calculates all primes and the sum of their logs up to the upper limit
#prints out the sum of the logs, the upper limit,
#and the ratio between the two

from math import *

def testPrime(x):
    factor = 2
    while factor**2 <= x:
        if x % factor == 0:
            return False
        else:
            factor = factor + 1
    
    return True


candidate = 3
primeLogSum = log(2)

n = int(raw_input("What is n? "))

while candidate < n:
    if testPrime(candidate):
        primeLogSum = primeLogSum + log(candidate)
    candidate = candidate + 2

print primeLogSum, n, primeLogSum/n

Thursday, November 4, 2010

OCW Problem Set 0

I am going to be posting my solutions for the OpenCourseWare class 6.00. I don't expect that these solutions are the best or that they are perfect, but as far as I know they are all valid answers to the problems put before me. There are several that could probably be optimized or improved fairly easily by an experienced coder, but as I explained in my last post, I am a very mediocre programmer. These problems are the first steps on my path to become better.

ps0.py
#Gets first and last name as input
#prints both names using concatenation

lastName = raw_input("Enter your last name: ")

firstName = raw_input("Enter your first name: ")

print(firstName + ' ' + lastName)
Edited 5 Nov, 2010 -- Updated the code formatting

Tuesday, November 2, 2010

MIT OpenCourseWare

I've been a mediocre programmer for a long time. I've never had to program for a living although I have occasionally written a script or two in the line of duty. The thing is that I feel really guilty for not being a good programmer. Not for any reason other than it comes fairly naturally to me and I'm outright wasting one of my best talents. I don't think that I would be the best coder ever or become famous for my ability to trivialize the most difficult of computing problems, but I do know that I could be pretty decent if I hadn't been too lazy to improve my gift. Peculiarly, I really enjoy knocking out a decent piece of code so why I've never pursued this with more regularity is a mystery to me.

With this in mind the last couple of months, I started looking around for a suitable method of refreshing my basic skills and then having an avenue for continual progression. The progression part always stumped me. I would enthusiastically engage in coding exercises and work my way through a language only to finish the material at hand and feel suddenly lost. The material I could find would either seem a repeat of what I had just done or far too complex for my current level. Traditional school wasn't an option (due to costs and time constraints) and I never came across anything online that fit my learning style. So I stayed in my rut and never allowed myself to improve.

Enter MIT's OpenCourseWare. OCW has been around for a while. Most people have heard of it, but like myself, many have disregarded it as a novelty or something outside their scope. On the contrary, it has turned out to be exactly what I've been looking for this whole time. I am very much a fan of structured learning. It has always led to my best successes. Unfortunately, I'm not a person that deals well with schedules and timetables. OCW is the answer in that I can use recorded lectures to get an introduction to a subject, then go and read up on it more in depth, write some code, and then continue on to the next lecture without being accountable to anybody else's schedule.

And they have virtually their whole catalog available in some form or another. I am working through the 6.00 Introduction to Computer Science and Programming class right now and am having a blast. The lectures are well taught, the material is presented in an excellent order, and the coding assignments are chosen and structured to be the perfect difficulty. It is also an excellent class for me since I am being introduced to OO concepts. OO has puzzled me for a while since virtually all of my experience has been with procedural languages (I am also currently reading The Object-Oriented Thought Process by Matt Weisfeld. I highly recommend it for a great introduction to OO concepts.)

A great thing about OCW is the one-stop shopping aspect of it. I am noticing that my math skills aren't quite up to par. After all, it has been almost a decade since I took Calculus and those types of skills degenerate quickly. No worries though. The solution is just a few clicks away with their 18.01 Single Variable Calculus course. I will have to purchase a textbook to work though, but the important part for me is the structure that is made available to guide you through the learning process. I am more than happy to invest the time required to learn skills that I enjoy practicing.

For anyone that is looking for a great way to independently study some subjects that aren't always easily accessible outside of universities, I highly recommend OCW. MIT has done a great job on them and is providing a fantastic service to the world through this program.

Wednesday, October 13, 2010

Piracy Is Not Theft

I found this today on The Pirate Bay Blog. While it's not really an argument against the copyright laws that blight our world, It does provide an excellent, memorable explanation of copyright vs. theft. Enjoy.

Sunday, October 10, 2010

What is wrong with us?

Today I found this post which covers some of our society's most serious ills with a simple question. What will the people of the future think when they look back at us?

Will they be astounded by the huge epidemic of fat people throughout our country? Probably not. Life will just become easier in the future and the number of overweight people will only increase. Why should we work out? It isn't necessary to our continued existence. Being fat isn't subject to ridicule or prejudice (obesity seems to be pretty much accepted these days). It's easy to be fat. The only solution I expect is constant surgeries or drugs to keep the weight down.

Police oversight is something that is absolutely necessary to avoid the level of brutality and corruption we have now. Even in more rural areas where police brutality was never as prevalent, it is becoming commonplace for the police to become militarized. All in the name of bigger budgets and even bigger budgets. These militarized police tend to forget their jobs of "Protect and Serve" and fall into a mindset of "Intimidate and Harass". They don't see themselves as part of the society anymore; they see themselves as keepers of the society, as parents watching over their n'er-do-well children. This is obvious in states where they uphold the illegality of recording a police officer often under the guise of wire-tapping laws. The police are felt to be above the laws they uphold.

And the drug war. So much has been said about this and yet, so many agree with the policies of criminalizing drug users. We have created a criminal class out of law-abiding citizens. Most offenders have never been convicted of anything besides possession. Our prisons are overflowing; we let murderers walk after a minimal sentence just to make room for that guy growing weed in his closet. Crime is the business of our courts and business is great. We should all be fighting to put some sense back into our courts.

Will our grandchildren look back at us and be surprised by our obvious faults or will they look back and not even imagine that it could be any other way?  These issues need to be fixed now or they will just keep growing and soon it will be "just the way it is".

Saturday, October 9, 2010

New Blog!!!

Just got back from three weeks in France. It was pretty amazing. I'd never been there before, and it was exactly what I thought it would be like and at the same time it wasn't even close.

I spent the first few days in Paris taking in the city and trying to get close to the experience of life as a Parisian. I've always preferred living as closely as possible to the locals as opposed to staying separate and only getting my glimpses through the tourist traps and foreigner-filled cafes. A tourist never really gets to enjoy himself thoroughly. You should live where the locals live, eat where they eat, go where they would go. Just take your time to walk around the city for a few hours without any aim at all. Those hours will be well spent.

After a bit in Paris, I journeyed down to Marseilles and was amazed all over again by this beautiful coastal region that was nothing like the urban sprawl of Paris. The Marseilles region is a marvelous series of towns spread throughout the mountainous coastline, and even being the second largest population center of France, it feels so much more rural than it is. The weather was great; the days were hot, the nights cool, and even the rain was ever so refreshing (what little there was). It was an entirely different experience from Paris and well worth the money to travel down there.

When I left Marseilles, I returned to Paris for a couple of days before heading up to Rotterdam, Amsterdam, and finally east to Berlin before making my return flight to JFK. All were fantastic places and each showed the diversity of Europe that is rarely seen so obviously in the states. In a future post, I'll give my thoughts on Amsterdam in particular. It truly is a holy land for smokers.
DreamHost Deals