Tuesday, December 11, 2012

Lunar Lander

Just made a lunar lander game thingy based on some of the constraints found at http://www.cs.carleton.edu/faculty/dmusican/cs111s10/lunarlander.html. /shruggies, took about 10 minutes.

basic lunar lander simulation based on constraints found at:

import sys

class LunarLander(object):
    'Lunar lander object'
    def __init__(self):
        self.altitude = 10
        self.velocity = 4
        self.fuel = 2
    def getVelocity(self):
        return self.velocity
    def getAltitude(self):
        return self.altitude
    def getFuel(self):
        return self.fuel
    def thrust(self, fuel):
        if fuel > self.fuel:
            self.velocity -= fuel * 4
            self.fuel = 0
        self.velocity -= fuel * 4
        self.fuel -= fuel
    def tick(self, fuel):
        self.velocity += 2
        self.altitude -= self .velocity
        #check for landing or crash
        if self.altitude <= 0 and self.velocity < 5:
            print 'skrrttt~ Houston, we have landed. ~skrrtt~ Victory! \'Murica! Fuck yeah!'
        elif self.altitude <= 0 and self.velocity > 4:
            print 'Oh no, you crashed!'
    def report(self):
        print '\nAlt = %d Vel = %d Fuel = %d' % (self.getAltitude(),
    def restart(self):
        restart = raw_input('Replay? Y/N >')
        if restart.lower() == 'y':
        sys.exit('game over!')
def main():
    print 'Welcome to Lunar Lander!'
    lander = LunarLander()  

    running = True
    while running:
        x = 0
        x = input('input thrust: ')


compiling binaries in the UNIX environment with gcc compiler... from the *nix command line! woot.

vim commands
:q quit, save
:w save
:q! quit without saving

i : insert mode
esc : command mode
h, j, k, l : movement in command mode
w, e : skip to the beginning/end of next word
f, n : find next instance of the word, goto Next instance
A : move to end of line and insert mode (A = append?)
$ : move to end of line
gg, G : move to beginning/end of the file

-i just realized i ought to write my blogposts in vim from now on....

UNIX terminal stuff
permission groups, directory bits
the command I should never ever use: "rm -rf /" aka "recursively remove everything from the contents of root"

./executable : execute file in the current directory?
rm - remove file
mkdir - make directory
cp file file2 - make copy of file to file2name
ls -la - list directory -l = long (permissions), -a = all
touch <filename.ext> : create file
vim <filename optional> : enter vim, edit file or create file
cat : output contents of file
| : (pipes) -> redirect stdout of one program to stdin or another prog1 stdout | prog2 stdin
chmod (a+x) : change permissions... ??
chown : change owners
sudo : "superuser do" -> execute program with root authority [not safe]

gcc complier stuff
makefiles are utility scripts that are used by gcc to compile / clean your binaries in a specified way
gcc looks for these files (in order): GNUMakefile, Makefile, makefile
can call with a certain  makefile in mind, e.g., makefile -f MyMakeFile <file to make>

Wednesday, October 24, 2012

Progress. Whoa..

It's been a bit of a hiatus, but I've been at it the whole time.  I'm finally starting to feel comfortable writing code.  That sounds a bit silly when I say it out loud; I've been reading and writing code on a daily basis for several weeks now.  And yet, I never felt a sense of mastery over the concept I was trying to model, or the solution I was trying to implement.  I've been unable to craft 100% exactly what I want into a set of precise instructions, though I've caught a glimpse of what that feels like here and there.

So there's this set of math-oriented programming challenges on the interwebs, called Project Euler.  I'm (slowly) completing them, one-by-one.  A maths wizard I am not, by any means, and I constantly feel like I'm in over my head when working some of these problems.  They get progressively harder in succession, and with every one of these I knock down, inevitable fist pumping ensues.

Here's 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 positive number that is evenly divisible by all of the numbers from 1 to 20?
Now the cool thing about Euler problems is they are open-ended in their implementation.  You can use any language, any model, and any algorithm, so long as you reach the correct solution.  I really like this method of learning, as opposed to a problem set like pyschools. Pyschools does a lot of hand-holding in helping frame the problem and shape your program.  Euler does not care about how you solve the problem in the slightest, and I think being 'stranded' in this way forces you to pull up your bootstraps and design your solution from the ground-up.  I think us beginner programmers face an uneasiness once we step out of Tutorial Land and into Outer Problem Space.  The only way to overcome this obstacle is to grab the nearest handhold and start climbing.

Anyway, I haven't yet reached a solution for this one, but I'm close.  Thus far, I've been able to write a small program to tackle the smaller problem: producing the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.  This gives me the ability to test a small-scale solution before I blow it up for the actual problem (all digits 1-20).

divisors = [2,3,4,5,6,7,8,9,10]

def euler_5(*divs):
    start = divs[0]
    for d in range(1, len(divs) + 1):
        start *= d
    g = 0
    for n in range(start, 0, -divs[0]):
        g += 1
        check = 0
        for d in divs:
            check += n % d
        if check == 0:
            ans = n
    print ans, g


In the first part, I'm trying to determine a starting number to begin testing for divisibility.  I ended up multiplying all the numbers in the range of divisors and counting down from there.  Why?  I wanted to begin with a number that I knew already had to be divisible by all the members of the divisor set.... plus that was just the first method I could think of.   This part could really use some work, generating a better guess is essential to having a fast iterative algorithm.

The second loop increments my guess counter, g, and then in a nested loop iterates through each element d in divisors, checking to see if they divide evenly.  This is accomplished through the modulus operator (%), which instead of returning the result of a division, returns the remainder only.  If a number passes all checks, I then store it in the variable ans, continuing on to see if I can find a smaller number.

I've been able to get it to spit out the number 2520 given a divisor list of the numbers 1 through 10, so I know it works.  My current problem is when I try divisors from 11 to 20 my initial guess is too high.  IDLE is giving me an error, I think the Python list object is unable to hold a range of numbers 670,442,572,800 digits long, and I wouldn't expect it to.  That's quite big.

So I've gotta figure a workaround for that, but confidence abounds!  Happy coding.

Thursday, October 11, 2012


Trying to get the basic shell of my poke_clone working, not coming along as easy as I expected.  In the process of trying to get it up on git so I can spam r/learnpython questions about my source, I found this little intro tut on how Git actually works as a VCS: Getting-Started-Git-Basics.

Tuesday, October 9, 2012

Scratchlist #1

So this is my scratchlist, which is a bunch of mental throw-up about stuff I'm working on, learning, and stuff I'm planning on learning next. Might as well write it down and keep track.

project: search engine
In the process of launching learning how to launch my basic search engine from Udacity CS101.  Need to work on receiving and handling queries via forms and familiarize with Google AppEngine's framework.  I do see a problem: I don't really know what I should use for my search corpus.  Ideally, this would be some set of pages whose links eventually terminate, but I can't have my web crawler crawling an infinite # of links.  I think I will have to implement some sort of 'depth-limiter' into the crawler to establish a stopping point for link-indexing.  How?  I don't know.

project: text-based Pokemon game clone
Main objective is practicing OOP-basics in Python.  Perhaps this can also be a good app to experiment on later when I learn some socket-handling and want to make it into a multiplayer game.  That'd really be cool, but I'll have to put that one on the back-burner right now.

project: blog platform
Developing in tandem with CS253 Web Applications class from udacity.com.  This is a great project to learn database interaction with.  I mean, a blog post is essentially a string of text, stored in a table somewhere, should be easy as pie, right? WRONG.

setting up my new domain!
I took the plunge and shelled out for my own domain. Probably a bit premature, but for now at least I have my own little playground.

the Command Line
I feel like science dog when I open terminal.  Forcing myself to do accomplish as much as I know how to do with a CLI instead of gui's... the main reason for this is so many tutorial and educational resources out there basically expect such knowledge, and I don't feel comfortable just entering sudo commands without knowing what effect they'll have.

This is another thing I want to learn in order to better understand what I'm learning (huh? paradox).  Lately I've come across a couple treasure troves of knowledge, all taught in java, which is a strictly-typed language unlike Python, which is dynamically-typed.

check out TheCherno's awesome gamedev tutorial series:  http://www.youtube.com/watch?v=GFYT7Lqt1h8

Tuesday, October 2, 2012


I don't understand Github. 

edit: I sort of understand Github.

Tuesday, September 25, 2012

I am science dog.

I'm taking the cs253 web development course on udacity.  Coincidentally, the lectures are being delivered by Steve Huffman, one of the founders of reddit!  He's really flying through the content, I'm struggling to keep up with a lot of the discussion.  Steve tends to glaze over details that I get hung up on -- it's like following a kid through a narrow corridor.  He keeps pausing, beckoning at you to follow, but the space gets ever narrower.  Case in point, google app engine's request handlers, lambda functions, template variables, and more.  My brain gets snagged on these and I have to take the time to research each one of them in turn, making sure I understand just to keep up with the exploding lexicon.

I am Science Dog.
As discouraging as my pace has been, it's been motivating to hear from one of the people who shaped the internet into what it is today.  One thing I really appreciate is Steve uses examples of things he learned while building his many web applications as lessons of what to do and what not to do.  And I'm sure that at one point, he was just as clueless as I am.  I hope.

Friday, September 21, 2012

Toes in the Water!

Here's my first progress update.

I've been following the CS101 - Introduction to Computer Science course on udacity.com.  I've just started Unit 6.  Thus far, we've learned so much about many new concepts that I haven't encountered in  any of the "Intro to Language X" tutorials out there.  I've come to the realization that just getting a program to perform the desired function is really only the tip of the iceberg.  Writing efficient, scalable, optimized, and understandable code is really going to be the hallmark of a pro vs. someone who's still fiddling with the basics.

These concepts are rumbling around in my head like sneakers in a dryer:
  • Architecture of data structures
  • Indexes & Hash Tables
  • Fibonacci Sequences
  • Recursion
We spent most of Unit 5 developing our own hash table from scratch, with create, update, and lookup functions based on a "bucket" system.  The idea behind it was to return a hash value that could be used to narrow down an index search.  When we finally got the thing up and running, the python data type dict was introduced and I'm sure I wasn't the only person having a "oh c'mon... I could have used this from the get-go" moment.

After implementing the dict in my index instead of a nested list, I really appreciated how fast it was to retrieve a value given a key.... and the fact that we built our own version of a dictionary is what allowed me to appreciate that.  I'm not completely sure what kind of algorithm Python is using to make searching easier, I just know there is one.  +1 Understanding!

Wednesday, September 19, 2012

Enter The Matrix

So there's this thing on the web called the Programmer Competency Matrix.  It's a skills rubric written by an experienced developer used to gauge one's mastery in certain programming competencies.  It's exciting to see all the skills I have to learn, but at the same time, quite scary that many of them might as well have been written in an alien language.

The Architect was the coolest guy in the Matrix.
A fitting continuum.  Noob on the left.

It's as good a test as any to gauge my starting abilities.  I'm happy to report that I'm not 2^n in every category.  I consider myself the highest level, log(n), in the area of Knowledge > Blogs :)  I have done some basic programming tutorials in a few different languages, i.e., html/css, php, javascript, mysql, python.  I have even taken what I consider a bit more in-depth look at Python, although my inexperience doesn't allow a good comparison.

Feel free to follow along, but this is mostly an indicator for myself.  Here is a chart of where I stand:

These squares won't mean much if you didn't follow the link.  There are some areas where I felt I didn't even deserve level 0, but others where I was a little between 0 and 1.  I erred on the side of conservatism.  Obviously, I was going to have 0 for Experience.  I did rather well in the 'meat' of Programming skills... probably because a lot of those categories have looser correlations with the actual art of developing software than others, like code organization.

There are a couple of reasons why I like this chart.  It shows me where my skills/knowledge/experience gaps are, thus providing an unsorted map of specific things I should try to dive into.  It's also a way to periodically check my own progress.  Perhaps I'll make it a habit to re-evaluate using this rubric every month or two.  Further, I think it's a great visual way to address the fact that I don't have a related degree to a potential employer.  I can't wait to fill this thing up... it's like a real-life video game!

On that note, I found this awesome blog post about Levelling Up As A Developer.

But, I'm getting ahead of myself.  It's time to hit the e-books.

Love at First Byte

Monday morning I turned twenty-eight years old.  Bleh, I'm not ready to be twenty-eight.  Granted, twenty-seven wasn't as great as twenty-six, but it sure as heck beats twenty-eight!.  That leaves me only one year and three hundred sixty-three days between now and the "Event Horizon", aka My Thirtieth Birthday.  Why am I not ready for it?  Well, the problem with thirty is you're supposed to have your act together.

In 1998, I was starting 7th grade and I began playing a sci-fi computer strategy game called Starcraft.  SC has since exploded into a hugely popular e-sport with millions of players and fans around the world.  But back then, it was a relatively new thing, and I spent a lot of time developing stratagems and studying the game's intricacies.  It wasn't long until I formed a star wars-themed "clan" (club of gaming nerds) on Blizzard's multiplayer network battle.net.  As the clan administrator, I felt it was necessary to have some place outside of the game to post rules and have group discussions.  So, I started my very first website, hosted on geocities.com, the path to which I've long forgotten.  This is where my story begins.

My website was a hideous thing by today's standards, but I was very proud that I didn't use a page editing program to do it.  I used plain ol' Windows Notepad and a tutorial on HTML to write that sucker.  It had nested frames, a hit counter, and a guestbook.  It even had a watermarked image of a galaxy that I was particularly proud of.  I literally felt like I knew what it was to be a hacker (sad, but true) the first time I looked at my page in source code.  I thought I was going to be the next Bill Gates.  How lofty are a 14-year-old's delusions of grandeur!

Well, sometimes life takes a more meandering route than we'd like.  Here I am today.  The deadline for becoming a billionaire genius-super-coder is long past.  I'm not a hacker, I'm not a coder, I'm not even an IT professional.  But still my interest persists.  I read programming tutorials and watch lectures on algorithms even though I don't have a clue what they're saying.  I'll read a particularly clever-seeming blog post and think, yeah, that could have been me.  

The fact is, that was true then and it's true now.  I'm giving myself two years to learn the skills necessary to get me into a career working with what interests me the most: computers.  I'm going to learn on my own as much as possible.  For me, writing helps me wrap my head around difficult topics.  This blog will be maintained as an open notebook for interesting things I come across, epiphanies, "doh" moments, and for posting snippets of code.  I am prepared to write a million "I don't get it" posts.  Hopefully, there'll be as many "Aha!" posts to go along with them.  And, I think people can profit from seeing my mistakes, as I have from so many others.

This is it.  The Event Horizon.  I'm probably going to feel dumber than I ever have in my life, but I've used up enough time feeling stupid.  Now, all I have left is serious.  It's time to get busy.