Matrices

Today I was reading Twitter and ran out of posts to view so I noticed my background. For more than a year my background has been a screenshot of this code:

MatrixMult.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class MatrixMult {
	static int[][] mult(int[][] a, int[][] b){
		int product[][] = new int[a.length][b[0].length];
		int temp = 0;
 
		for(int row = 0; row < product.length; row++){
			for(int col = 0; col < product[row].length; col++){
				for(int i = 0; i < a[0].length; i++){
					temp += a[row][i] * b[i][col];
				}
				product[row][col] = temp;
				temp = 0;
			}
		}
		return product;
	}
}

You might be able to tell from the name that it multiplies matrices together. Even though I wrote this quite a while ago I still remember how much fun it was to write. It was an assignment near the end of my AP Computer Science class during my Junior year of High School. I remember getting a working method withing a few minutes like any other assignment but it was ugly and I saw opportunity for improvement.

I went through several revisions making my code faster and more concise each time until I ended up with something I could be proud of. It turns out what I enjoy most about programming is not creating applications or games but solving difficult problems with good code.

Seeing my old code reminds of the time I solved the first programming mission on hackthissite.org. I spent some time working on it and a few months later while learning about popular algorithms in AP Computer Science I realized that I had independently derived the bubble sort algorithm. I also remember a challenge from cplusplus.com that intentionally led the ‘player’ to the binary search algorithm but I didn’t know it at the time and had a lot of fun making it on my own.

What I’m saying is the three times I remember having the most fun writing code were all optimizing an algorithm. Its just not something I expected when I first learned of programming during a game of Interactive Buddy nearly four years ago.

Categories: Uncategorized | Tags: , , | Comments RSS

Post a Comment

Your email will not be published. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
LaTeX is also allowed inside \( \) or $$ $$ tags.