Tuesday, March 17, 2009

Sometimes They Come Back

So I'm working through a great Python book by Andy Harris, and I'm running a little orbit simulator.

You can the original orbit that my space ship was in (the oval shape that fits on the screen). I hit the thruster a bit too much and altered the orbit (the oval that goes OFF the screen). My ship seemed lost in space and time, as I started to think about Kepler's brilliant 2nd law. In short, if my ship was to return, it would be a while.

Python, however, deals well with really large numbers. If your program requires them, Python will supply them. Printing a googol in Python is no problemo. So I waited.

And waited.

And waited.

My wife came in and asked me to help her move some furniture in our guest bedroom. Later, I came back and the orbit was complete: my ship had returned home. Sometimes they come back.

Sunday, March 15, 2009

Pygame for Flocking Behavior Simulation

Back in the 80s, Craig Reynolds did some great work on simulating the flocking behavior of birds on a computer. I've always been fascinated by his results, as they look so much like a real flock of birds.

Since then there have been numerous implementations of his approach.

While programming Alice with a student recently, we came up with a way to simulate fish swimming in schools. Our method was nowhere near as complicated as flocking boids, but it was quite effective nonetheless. It merely involved random movement with boundary checking: get too far away from the "center" and the fish decided to head back towards the "center". Of course the "center" here may be a physical location, or the average location of the fish.

To study this in more detail, I decided to use Pygame, a module for Python. Pygame makes writing little graphical simulations a piece of cake. Add to it the functionality of Numpy or Scipy and you have a very powerful environment for scientific simulations.

Tuesday, March 10, 2009

My Ping Pong Problem

While writing up some new and original logic problems for the PyWhip site, I came up with this one, which kept several teachers in our math department (and a student) entertained during lunch:

Imagine that we have some ping pong tables and need to have them "sealed" before the next round of competition. It takes one worker 10 minutes per table to get it properly sealed and cleaned up. It takes two workers 5 minutes per table, as they can each work on a half. Only two workers can work on a table at one time, though, so three workers also would take 5 minutes on one table. All we care about in this problem is how long it takes for the work crew to be done with the table "resealing" job so we can get the next round of a tournament started.

Your job:

Write a function that accepts two parameters (numberOfWorkers , numberOfTables) and have it return the total number of minutes it will take for the work crew to get the job done.

Saturday, March 7, 2009

PyWhip and Javabat ?!

If you are a member of Edu-Sig (the Python in Education group), you may have heard talk recently about creating a Python alternative to JavaBat, a tool used by almost every AP Computer Science teacher on the planet.

JavaBat is almost universally loved and used by high school APCS teachers. Students can sign up easily and then start solving the 250+ challenges they are presented with, ranging from simple String manipulations to hard core recursion methods.

One of the difficult aspects of Java is that it never was designed as a nice language to quickly write up some code and let it run. Old farts will talk about the golden days of BASIC, but Python is really a great language for Computer Science education. Javabat helps by letting students write simple methods (functions) without the need to enclose everything in a Java class with public static void main (String[] args) . In short, it let's students and teachers focus on the login involved in a particular method--which is a good thing. Teachers can track student progress, browse their code, etc.

So the reality is that Javabat is one of the most used tools for teachers of AP Computer Science. I have yet to meet a teacher of APCS in my state that does not use Javabat.
If Python is to ever gain a foothold in secondary school CS education, having a Python alternative to Javabat is a very good idea.

Right now it's just beginning, but if you want to contribut to PyWhip, head on over to edu-sig or contact me on how to get involved. Since I haven't really asked the two main contributers for permission to put there contact info here, I'll leave their names out of this, but they're doing a great job on this so far.

Friday, March 6, 2009

Thank You! BlueJ and Greenfoot open up.

I just stumbled across this announcement about BlueJ and Greenfoot going open source. These are two applications used by many teachers of AP Computer Science classes. In the past they were always "free" as in free beer, but the source code was not available. Opening up their code can only help spread the use of these two wonderful programs.

Many times in the past I've contacted Ubuntu users in the Ubuntu forums for help on issues with BlueJ and Greenfoot. The response has always been a bit reserved--show us the code and maybe we can help. This change of policy will immediately build acceptance from a very talented group of developers and programmers.

Also, it's just plain fun to read the source code. Michael Kolling and John Rosenberg have written code with much better documentation than you will usually find. Here's just one example:

* Java 1.4 & prior version of trinary "? :" operator. See JLS 2nd ed.
* section 15.25.
* @throws RecognitionException
* @throws SemanticException
private JavaType questionOperator14(AST node) throws RecognitionException, SemanticException
AST trueAlt = node.getFirstChild().getNextSibling();
AST falseAlt = trueAlt.getNextSibling();
ExprValue trueAltEv = getExpressionType(trueAlt);
ExprValue falseAltEv = getExpressionType(falseAlt);
JavaType trueAltType = trueAltEv.getType();
JavaType falseAltType = falseAltEv.getType();

That was interesting. This comment here was also fun to find:

* Find the Wireless Toolkit. In Windows we search all the filesystem roots.
* In other systems (Linux, that is) we search the directories in the
* initializer list of array 'roots' listed below.

I've got a lot of reading to do, it seems.... :-)