Pascal Source Code

{* Author: Hannes du Plooy *}
{* Date: 20 Sep 2016       *}
{* Objective: To solve the towers of hanoi with number of discs provided in the arguments to calling the program *}
program hanoi;

Uses sysutils;

procedure hanoi(source,dest,other,discs: Integer);
begin
    if (discs > 0) then begin
        hanoi(source,other,dest,discs-1);
        WriteLn('Move ',source,' to ',dest);
        hanoi(other,dest,source,discs-1);
    end;
end;

begin
    if (ParamCount < 1) then begin
        WriteLn('Please provide the number of discs');
    end
    else begin
        hanoi(0,2,1,StrToInt(ParamStr(1)));
    end;
end.