My first non-frivolous program in Ruby !!!

It has been done. (on Suse Linux 9.1 so Win Users have to deal with the newline diff)

The problem was taken from Starter Problems
To find a way thru a maze from point s to e. I tweaked the problem to read the maze from a text file (say "Maze.txt". The PathFinder creates a Maze object from the file, finds a way thru it and outputs the maze with the solution to a new text file (e.g. named 'Solution to Maze.txt" as per the input filename). The PathFinder is able to deal with mazes of any height or width as long as it is rectangular.

To do a sample run,
p =
p.findPath( "TestMaze.txt" )
This would create another text file named "Solution to TestMaze.txt" with the solution .

Under Influence of XP

Was simultaneously reading Ron Jeffries' book (see previous post) :). I did this the XP way, by which I mean I had a test store that I kept stashing test cases into as I went along.
TestPathFinder.rb - run this via
ruby -w TestPathFinder.rb
for a test run. I could not find a NUnit like testRunner, for the red, green, refactor steps. So I made something really basic myself.. which I feel is pretty neat and helped me a lot.
The entire process took about 3 hrs including the tests, which is not bad by my standards.
The code has minimal comments at the same time, I feel it is quite readable. The only places I used comments are
  • to blow my own trumpet in the file header
  • I could not find a way to represent characters other than by using ASCII codes (71 instead of 'G'). Found another solution where he overcame this by using "G"[0].. (eww..)
Now how do I put a zip online so that it is free for everyone to access. Any ideas anyone ? Till I find something, drop me a mail if you are interested at
gishu underscore pillai at yahoo dot com

No comments:

Post a Comment