## Category: misc

### Awari

###### Written by Tracy Poff in misc on Sat 13 February 2010. Tags: awari, BASIC, porting,

Trying to decipher an ancient implementation of Awari in a dialect of BASIC I’m not familiar with. Fun!

### LETTER, a simple guessing game

###### Written by Tracy Poff in misc on Thu 11 February 2010. Tags: python, game, porting, BASIC,

Recently, I’ve been looking through a book called Basic Computer Games: Microcomputer Edition, edited by David H. Ahl. The book contains lots of type-in computer games written in Microsoft BASIC for the Altair. A fair number of these ‘games’ are more like toys, and some aren’t even interactive, but a few look like real fun, and they’re all little pieces of computing history, which I find very interesting.

I thought I’d port a few of the more interesting games to a more modern language so people could check them out and see how far we’ve come (or, in some cases, how far we haven’t come). Of course, I thought I’d start by doing exactly what I didn’t set out to do, and port a very simple and not very interesting game, just to get a feel for it. Even this gave me a little pause, as I’ll get into. First, the game: Letter, by Bob Albrecht. That link leads to a scan of (a different edition of) the book I got the game from, so you can see the original BASIC code I was porting. Programmers among us will recognize that it’s extraordinarily simple, and, for a BASIC program, quite clean and readable. One thing gave me a little trouble:

510 FOR N=1 TO 15: PRINT CHR\$(7);: NEXT N</pre>


This line didn’t seem to affect the output in the printed sample run of the game, so I got an Altair emulator, just to be sure. Indeed, it doesn’t actually print, though I have no idea why. Whatever the reason, I left it out so as to faithfully reproduce the game as it was on the original system, whatever the code says.

A part of my intention in porting these is to provide sample code for people who may be interested in learning to program; these simple games should prove to be pretty easy to understand for anyone who cares to look. Having just read through quite a lot of BASIC code, I wasn’t in a very pythonic frame of mind when writing this, but I think it’ll be clear enough.

Enough about my troubles, though. You can find the game here. If you have python installed, you can just get the tiny python source file. If not, or if you’re not sure, you can get a ZIP with a Windows executable, instead, which should run on anything from Windows 95 through Vista. If it won’t run, or complains of missing files, you may need this.

I’ll port something more interesting, and hopefully more fun, next time. Until then, I HAVE A LETTER. START GUESSING.

### A Fast Algorithm for Computing Fibonacci Numbers

###### Written by Tracy Poff in misc on Sat 10 October 2009. Tags: python,

I came across an algorithm for computing Fibonacci numbers in a paper by Takahashi Daisuke; the paper’s in Japanese, but the pseudocode of the algorithm is plain enough that it’s easy to understand, even if I can’t read any of the explanation. I’ve implemented it in python, and it’s decidedly slower than the Fibonacci function in Mathematica, though that’s to be expected. My implementation takes quite a few seconds to compute F(2^20) but is quick for numbers below about F(2^15), with the additional benefits of not computing absurdly huge floats or recursing a million times.

The algorithm is apparently a refinement of another (perhaps well-known?) algorithm, which computes Fibonacci numbers from the product of Lucas numbers. I’ll have to look into it to see just how it works.

Edit: After some investigation, a large part of Mathematica’s apparent advantage is in its faster display, rather than faster computation, though Mathematica does still beat my python program by a rather huge amount—Mathematica computes Fibonacci[2^23] in about 0.2 seconds, while my program takes just over five seconds. This disparity increases as the argument grows larger. Also, found an English version of that paper. Neat.