?

Log in

No account? Create an account
patrickwonders
patrickwonders

There is too much Perl in Perl.

Perl has a reputation for looking like line noise. Of course, one can write Perl that's moderately readable. But, Perl has a much deeper relationship with line noise than just the superficial appearance.

If you take a heap of line noise and drop one character, is it still line noise? Yes (unless you had only one character in the heap, then things get a little zen about whether no noise is line noise). If you take a heap of Perl and drop one character, is it still Perl? Very likely (even if you only had one character in the heap).

Code sample in support of said thesis...Collapse )

Some time back, I was talking about Perl's permissiveness to a non-programmer. He said, That must make it really tough to get something to compile. I said, On the contrary, almost anything you type compiles. It just does something different than you had intended it to do. Perl reminds me of this at least once a week.


patrickwonders
patrickwonders

More code visualization...

Adding onto my recent post, I now have some code which reads the output from dprofpp -t. So, if you've got some Perl code that you'd like to visualize the calling structure of, you can profile it, run a script to turn the dprofpp(1) output into a nice set of Lisp forms, and run another script to show those forms with the GLUT viewer.

Here's the results from a run of one of my cron jobs. My cron job usually runs against 134,000-ish students and teachers. This profiling info was from just those whose email address begins with 'a'. But, that's a big enough hunk that the actual results are probably really close to this.

Perl profiling output viz

The latest version of the code is v0.6.2008.05.07. Alas, it looks like I should expand(1) everything before uploading.

Tags: ,

patrickwonders
patrickwonders

A Card Dealing Game

On a recent episode of The Math Factor podcast, they discussed a very simple game. Start with a deck of some number of cards and a round table of some number of people (preferably more than one of each). The dealer deals one card to each player (going around clockwise starting with the player on the dealer's left) until all cards are dispersed. The last person to get a card is the new dealer. The new dealer picks up the cards she has been dealt and deals those out in the same manner. Play continues until someone has all of the cards.

Because each position can only come from one parent position and can only lead to one child position, you are guaranteed that you will always get back to the starting state if you play long enough. Someone else may win before that, but you are guaranteed that you will never get into a loop where no one will win. Or, I should say, that is so long as no one misdeals.

It turns out that for two players with 52 cards, the game should take 12 turns if everyone deals correctly. But, I wanted to explore all of the possible loops you could get into with a misdeal. There are 15 different loops altogether. Each is summarized by one row of this image:

loop summary image

A dot in the zero-th column means that the first dealer has 0 cards and the other player has 52 - 0 cards. Similarly, a dot in the n-th column (starting the counting with zero) means that at some point in the cycle, the first dealer would have n cards and the other player would have 52 - n cards. The dot is blue if the first dealer has the deal and red if the second player has the deal.

With a different number of cards, situations arise where the first-dealer has n cards and the deal but later has n cards but not the deal. Those would be depicted as yellow in my scheme. But, that doesn't occur with 52 cards. Try two players and 2 cards to see how it could come up.

Things one can tell from the picture...Collapse ) Code that generated thisCollapse )