Archive for January, 2009

Pinball Wizard

Almost nobody is “good” at pinball. For the most part, people who plug quarters into pinball machines suffer from a sort of selective amnesia. The Goldberg-machine-like complex of tracks and flippers and fun contraptions lures you in narcotically. It’ll be fun, you tell yourself, just one game. Thirty seconds later, you curse disgustedly as your last ball slips past your helplessly thrashing flippers, leaving you angry and out of quarters and not even one hundredth of the way to a high score. You vow never to play another game, yet the next time you’re in a bar or an arcade, you’ll find yourself feeding quarters into a pinball machine, chasing some mythical fun you’ve never actually had like a crazed junkie.

Why is that? Pinball machines are rigged to win, just like all arcade games. Yet unlike video game machines in which the game’s advantage is hidden deep inside the circuits that run its code, the pinball machine’s edge is purely mechanical and, what’s worse, flaunted openly. There are times when no matter how or when you flick your flippers, the ball will bounce right through the space between them. The scoring is so arcane, complicated, and specific to each machine that it’s effectively arbitrary. The bumpers conspire against you. And lest you forget who’s boss, that track that runs along the outside of the bottom flippers is there to remind you—do not pass Go, do not collect a hundred dollars.

You can’t learn a pinball game the way you can a video game. There is no algorithmic predetermination—the super bomber doesn’t always appear from the top right when the music gets ominous. “Good” players do improve their chances with judicious (and subtle) hip checks (lest they incur a tilt penalty or the wrath of the arcade manager). But ultimately, and this is I think the reason why pinball has endured in the digital age, the pinball machine and all its flashing lights are just a intermediary between the player and the inexorable laws of the universe. You are competing not against a programmer’s code but against gravity and mechanical advantage—and the odds are stacked against you. But, buoyed on perhaps by the elusive promise of an extra ball and the satisfying physical sensation of a well-timed flick, you’ll stave off the inevitable Game Over for as long as you can, because you know one day there’ll be no more quarters.

A Few Good Lines

For my first assignment in Programming A to Z, I wrote a command line script that searched the text of Aaron Sorkin’s screenplay A Few Good Men for occurrences of the word “truth” and then sorted the resulting lines alphabetically by the fourth word (to bolster the appearance of serendipitous poetic randomness and to ensure that lines shorter than four words—possible titles—appeared at the top) and eliminated any duplicate lines.

Applying the following to the screenplay:

grep "truth" -i <afgm.txt | sort -fd -k 4 | uniq >sorted.txt

produced:

the truth.
we’d all just as soon hear the truth.
I can to bring the truth to light.
truth, and nothing but the truth so help
And the truth is this: your son is dead
That’s a distortion of the truth. Private
night. Jessep was telling the truth. The
You can’t handle the truth!
You don’t want the truth. Because deep
You can tell the truth, corporal, it’s
Court-Martial will be the truth, the whole
I want the truth.
searching for the truth.
Ain’t that the truth. Catch you tomorrow.

Sorting by the second word instead of the fourth:

grep "truth" -i <afgm.txt | sort -fd -k 2 | uniq >sorted.txt

produced this poignant meditation on epistemology and the search for meaning:

That’s a distortion of the truth. Private
we’d all just as soon hear the truth.
truth, and nothing but the truth so help
You can tell the truth, corporal, it’s
I can to bring the truth to light.
You can’t handle the truth!
You don’t want the truth. Because deep
searching for the truth.
night. Jessep was telling the truth. Tne
Ain’t that the truth. Catch you tomorrow.
And the truth is this: your son is dead
the truth.
I want the truth.
Court-Martial will be the truth, the whole

I also ran this slightly modified version to similarly search for “code red”:

grep "code red" -i <afgm.txt | sort -fd | uniq >red.txt

The result captures not only the intensity of the film but also the sometimes comedically repetitive rigamarole of a legal system based on hearsay before ending with an unfinished accusation that alludes to the undercurrent of guilt, the symbolic “blood on our hands” that underpins the Judeo-Christian West. Good work Aaron Sorkin.

6th, receive a code red?
A code red was ordered by my platoon
about code reds? On the record I tell you
code red…
considered a code red?
Did Kendrick order the code red?
Did you order the code red?
discusses code reds.
Do you know what a code red is?
give Santiago a code red.
give Santiago a code red?
Have you ever ordered a code red?
Have you ever received a code red?
is to perform code reds?
Jessep told Kendrick to order a code red.
Kendrick ordered the code red, didn’t he?
marine would get a code red?
My point is that I think code reds still
ordered the code red.
sounded an awful lot like a code red.
the term code red and its definition in
to give Santiago a code red?
told them to give him a code red.
Was it a code red?
Willy Santiaga code red?
with code reds, please.
You got a code red ’cause your palms were

Introduction to C

So I thought C was going to be impossible to understand, but so far (which is admittedly not that far), it’s not too different from the other programming languages I’ve encountered—though malloc (it even sounds ominous) and all the $ and * loom threateningly over the horizon.

I’m struggling with the finer points of pointers (more a syntactical problem I think than a conceptual one), as is evident from my first piece of C code, which takes a string (right now one that’s hard-coded into the program) and reverses it. I realized while I was coding that what takes so long about learning new languages is figuring out how to do the little easy stuff you take for granted. For instance, I wanted to find the length of the array in which I was storing my string but had no idea what the syntax was in C (I have since learned you can use sizeof()), so I ended up writing my own function instead.

This is the code:

/*
THE UGLIEST STRING REVERSER KNOWN TO MAN (OR MACHINE)
by alex kauffmann

This is a totally inelegant solution but it
works, though I couldn't fully wrap my head around
the pointers (which is why I have both an array and
a more C-ish asterisk thingie).  
 */

#include <stdio.h>

void main() {

  int i,a,b;
  char *s;

  s="satan oscillate my metallic sonatas";

  printf("The original string is: %s\n", s);
  printf("The reversed string is: ");

  for (i = 0; *s != '\0'; s++)  // counts the characters
     i++;                       // in the string

  char rs[i];                   // holds the reversed string

  for (a=i; a>0; s--) {
     rs[i-a]=*(s-1);            // (s-1) offsets the first
     a--;                       // character to skip the '\0'
  }

  for (b=0; b

Bugging out, now with sound!

In preparation for my return to school on Tuesday, I wanted to ease myself back into the swing of things by playing a little with Processing, so because I never got around to playing with sound last semester, I added some sound effects to my cockroach sketch using Minim.

Check them out here.