Month: August, 2009

The Towers of Hanoi in Erlang

18 August, 2009 (22:34) | Programming, Erlang

I’m just playing with Erlang, below is my attempt at solving the Towers of Hanoi puzzle using it. Call it using hanoi:hanoi([1,2,3,4,5,6],[],[]) (a valid starting position is assumed).

-module(hanoi).
-export([hanoi/3]).

hanoi(A,B,C) ->
Disk=lists:max(A),
move(Disk,A,B,C).

move(Disk,[Disk|Source],Dest,Temp)->
[Source,[Disk|Dest],Temp];

move(Disk, Source, Dest, Temp) ->
[S1,T1,D1]=move(Disk-1,Source,Temp,Dest),
[S2,D2,T2]=move(Disk,S1,D1,T1),
[T3,D3,S3]=move(Disk-1,T2,D2,S2),
[S3,D3,T3].

Solving the Towers of Hanoi puzzle in C#

4 August, 2009 (18:45) | .Net, Programming, C#, Computer Science

I thought this would be a fun little exercise to try. This puzzle is generally used to teach recursion in CS classes, but I have never actually tried to implement it.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TowersOfHanoiCs
{
class Program
{
static List […]

Sending an email with syntax hightlighting for your source code

2 August, 2009 (22:53) | Programming

I resisted the switch to HTML e-mail for as long as I could, I know there are some who have managed to succeed in not switching to an HTML enabled email reader. But I just couldn’t hold out due to the fact that there were so many non-computer savvy people I communicated with who […]

Turbo Pascal 5.5 is available for download for free

2 August, 2009 (22:23) | History, Programming

Firing up ole’ TP7 for the last post put me in a nostalgic mood, and I went looking to see where Turbo Pascal stands today. It doesn’t look like you can still buy it, and the only version available is Turbo Pascal 5.5 which you can download for free from: http://edn.embarcadero.com/article/20803
I believe my first […]

Statements in most languages can be empty

2 August, 2009 (19:31) | Programming

I was looking through some code that was posted for review when someone had pointed out a statement like the following:

int x=5;;

Note the two semi-colons. I initially thought “Great, someone has us reviewing code they didn’t even try to compile.” But to my amazement, it does compile, and it compiles in pretty much […]

A really tough puzzle

1 August, 2009 (21:37) | Humor

100 prisoners are each locked in a room with three pirates, one of whom will walk the plank in the morning. Each prisoner has 10 bottles of wine, one of which has been poisoned. And each pirate has twelve coins, one of which is counterfeit and weighs either more or less than a […]