The earliest memory I have of ‘programming’ is in the early/mid 90s when my father brought home a computer from work. We could play games on it … so of course I took the spreadsheet program he used (LOTUS 123, did I date myself with that?) and tried to modify it to print out a helpful message for him. It … halfway worked? At least I could undo it so he could get back to work…

After that, I picked up programming for real in QBASIC (I still have a few of those programs lying around), got my own (junky) Linux desktop from my cousin, tried to learn VBasic (without a Windows machine), and eventually made it to high school… In college, I studied computer science and mathematics, mostly programming in Java/.NET, although with a bit of everything in the mix. A few of my oldest programming posts on this blog are from that time.

After that, on to grad school! Originally, I was going to study computational linguistics, but that fell through. Then programming languages (the school’s specialty). And finally I ended up studying censorship and computer security. That’s about where I am today!

But really, I still have a habit of doing a little bit of everything. Whatever seems interesting at the time!

Pickles and memoization

Memoization (yes, that’s the correct word) is a method of optimization in computer science where the first time you run a function you cache the result. After that, rather than re-doing the work, you can simply return the previous result. It’s not always perfect as you’re trading time for space.

read more...


Line art with an HTML5 canvas

Let’s play with HTML5 canvas elements!

Basically, I want to draw some simple line diagrams. Go from top to bottom on one side while going from right to left along the top or bottom. It sounds complicated, but perhaps it’s easier to explain with a drawing:

read more...


n-queens in 18 lines of code

One of the rites of passage for computer scientists it seems is to solve the Eight Queens Problem–where you must place 8 queens on a chessboard so that no pair of queens is attacking each other. Even better is when you can expand that to the n-queens problem with n queens on an n by n chessboard. After finding it again in older posts on both Programming Praxis and DataGenetics, I decided to go ahead and take a crack at it and I think the solution is pretty straight forward.

read more...


Sampling stdin

A relatively simple script today. When I was working with Twitter data, it quickly became apparent that it’s a lot of data. So I needed some way that I could reduce the amount of data that I was dealing with while still keeping many of the same properties. To that end, I wrote a really simple script that would forward lines from stdin to stdout but would only do so a given percentage of the time.

read more...


A piece of the abc conjecture

There’s been a bit of hubbub in the in the math world the last few weeks with Shinichi Mochizuki's 500 page proof that of the ABC conjecture. Basically, the conjecture states that given three positive coprime integers a, b, and c such that a + b = c, the product of the distinct prime factors of a, b, and c is rarely much smaller than c. While this may sound strange, there are a number of interesting consequences that you can read about here.

To make a long story shorter, there was a challenge on Programming Praxis that intrigued me, which was to write code that given a upper bound on c would generate a list of all of the triples (a, b, c) such that the product is larger.

read more...


Who wants to win the lottery?

So everyone would love to win the lottery right? Just think of what you could do if you had even $1 million dollars to spend. You could buy a dozen tacos a day at Taco Bell for the rest of your life. And your children’s lives. And their children’s lives. 228 years to be more precise. Or you could pay to send the entire family from Cheaper by the Dozen to the average state university–even if they each took an additional two years to graduate. And that’s just for $1 million. Payouts are usually much higher than that…

So what’s the catch?

(If you came here just for the Powerball simulation, it’s down at the bottom of the page. Click here to go straight there.)

read more...


A needle in a Pi-stack

Recently I’ve been watching a lot of find-in-pi source code (require racket/generator) (define (make-pi-spigot) (generator () (let loop ([q 1] [r 0] [t 1] [k 1] [n 3] [l 3]) (if (< (- (+ (* 4 q) r) t) (* n t)) (begin (yield n) (loop (* 10 q) (* 10 (- r (* n t))) t k (- (quotient (* 10 (+ (* 3 q) r)) t) (* 10 n)) l)) (loop (* q k) (* (+ (* 2 q) r) l) (* t l) (+ k 1) (quotient (+ (* q (+ (* 7 k) 2)) (* r l)) (* t l)) (+ l 2)))))) Simple enough to use, we can use Racket’s for to generate a list of n digits of pi or to convert the same to a string:

read more...


Expanding L-systems

An L-system is essentially a set of rewriting rules that turns a simple set of rules into a complex pattern. They’re generally used for generating self-similar fractals, including plant life, but I’ve also seen them used in programming languages research where they can generate valid programs given the grammar of a language. They’re also rather similar to turtle graphics in that many of the sample graphics that I’ve generated in the past are based directly off the L-systems page on Wikipedia. So this time I’ve decided to work on a relatively simple macro that can be used to expand simple L-systems.

read more...