January 10, 2007

A Late First Snowfall

Some flakes are falling outside my window in Philadelphia. It is the first snow I have seen here this year, but it isn't sticking. My kids are hoping for some real snow soon.

Today NOAA reported that 2006 was the warmest year on record in the U.S. Have you noticed that people are talking about global warming a lot this winter?

I would have thought that the sweltering days of summer would have inspired more thoughts of global warming. But it looks like what really gets peoples' attention is unseasonable warmth during the winter. The query "global warming" on Google Trends follows a cycle, with the least interest during the summer and the most interest in the winter months.

Posted by David at 12:35 PM | Comments (0)

The Lebanese Street

As the rainy season arrives in Lebanon, the Lebanese opposition protests have dwindled in size to a few hundred full-time protestors, joined by a festive crowd of opposition supporters in the evenings. The soldiers that watch over the protests stationed in their APCs are now described as somehow more relaxed in their mission to keep the peace. And Hizbollah's promised escalation of citywide protests at government ministries this week have turned out to be small, peaceful affairs so far.

This continuing not-news in Lebanon seems like history in the making to me.

The anger on the street that began as a rolling boil with assasinations and millions in the streets of Beirut has now been reduced to a simmering stew, a melting pot of sorts. I found this opinion piece by Rami G. Khouri in the Lebanon Daily Star a colorful and optimistic take on the situation. He suggests that with the food and music and barbed wire and tanks, the extended presence of both peaceful opposition protesters and soldiers has transformed the center of Beirut into strange sort of "paradise" of urban congregation. He seems to believe this will lead to an inevitable compromise if given enough time (without foreign meddling), and that this might be the beginning of a more robust and peaceful Lebanese democratic ethos, maybe even a "beacon" of future, more peaceful democratic powersharing in the Arab world.

Posted by David at 09:59 PM | Comments (0)

January 18, 2007

Learning to Program

Everybody should know a little programming.

Last year I visited my son's second-grade classroom to teach an hour of Logo, and it was a blast. So tomorrow, I am going to try again. This time, instead of using Logo, I will be trying to teach a small group of third-graders the basics of python.

Teaching python means that it will be a taste of real programming without the sugar-coating of "educational" software. I have two hours instead of just one, but python was designed for pros, not kids. Will the kids be able to learn it? We shall see.

Our goal will be to finish a simple game - hangman.

I have posted my Learning to Program with Python walkthrough here.


Yay, what fun. Teacher Bob MacNeal posted some pictures here.

More thoughts on teaching python below.

Continue reading "Learning to Program"
Posted by David at 06:37 PM | Comments (5)

January 27, 2007

RPS Battle of Wits

For a little programming fun, try playing the Online Rock-Paper-Scissors Battle of Wits.

Back in 1999 and 2000, Darse Billings introduced the world to computer-RPS in the First and Second International RoShamBo Programming Competition. You might imagine that rock-paper-scissors is too simple a game to be worth building computer players. But you would be wrong.

How to Win at Rock-Paper-Scissors

True, it is impossible to build an algorithm that dominates the simple random player, but it is also impossible for the random player to dominate any other algorithm. In any tournament that includes nonrandom players, you can win by detecting the nonrandom strategies and beating them.

For example, if your opponents are the random player and good ole' rock, you can win the tournament by just playing "always paper." When you go up against random, you will be evenly matched. But you will dominate rock - that is better than random can do, and so you win overall.

Of course "always paper" and "always rock" are defeated by my daughter Piper's favorite RPS strategy, which is to make the move that beats her opponent's previous throw. Here is her algorithm, written in python:

import rps, random
last = random.randrange(3)
for turn in xrange(rps.turns):
  last = rps.play(rps.beat(last))

In this code rock is 0, paper is 1, and scissors is 2; rps.beat(last) returns the move that beats "last"; and rps.play(n) plays our move and returns our opponent's.

Piper's "beat last" algorithm is ruthlessly aggressive. On the other hand, it is also very predictable, so it will lose to a player who knows how to provoke it....

Continue reading "RPS Battle of Wits"
Posted by David at 12:45 AM | Comments (0)