Lima Bean
2011-10-15 08:15:54
Simple:
1. Cut
2. Paste
3. Play
1. Cut
2. Paste
3. Play
program PegtoySimba;
{Pegtoy Simba Edition 1.0.9 by Lima Bean}
{1.0 - 1.0.8}
{added times}
{move action now in Status}
{added failsafe for int input}
{Disc input added}
{min max added}
{commented out some code}
{some reordering done}
{Error pointed out by masterBB}
(*
Just uncomment the various lines in Pegtoy
to see differences in time.
Important to note, this is coded for Simba.exe
without any dlls, plugins, etc.
Enjoy.
Lima Bean
*)
var
m, n, stime, rtime, ftime: Integer;
value: string;
Procedure Pegtoy(Lfm, Lto, Lus, n: Integer);
begin
if n > 0 then
begin
Pegtoy(Lfm, Lus, Lto, n - 1);
m := m + 1;
//Status('move ' + ToStr(m) + ' ' + ToStr(LFm) + ' --> ' + ToStr(Lto));
//Writeln('move ' + ToStr(m) + ' ' + ToStr(LFm) + ' --> ' + ToStr(Lto));
Pegtoy(Lus, Lto, Lfm, n - 1);
end;
end;
Procedure GetDisks();
begin
InputQuery('Disk Count', 'Please Enter Number of Discs(31 or less)', value);
if value = '' then
getdisks;
if (chr(47) > value) or (chr(58) < value) then
showmessage('Numbers only. Thank you')
else
n := StrToInt(value);
if (n = 0) then GetDisks();
if (n >= 32) then
begin
Showmessage('That is not avaialbe at this time. Thank you');
n := 31;
end;
stime := GetSystemTime;
end;
begin
ClearDebug;
GetDisks;
writeln('Start Time : ' + ToStr(stime));
Writeln('Solution should take: ' + ToStr(pow(2.0,n)-1) + ' moves.'); // masterbb
Writeln('Solving for ' + ToStr(n) + ' discs with 3 pegs');
Pegtoy(1, 3, 2, n);
Writeln('Solution verified: ' + ToStr(m) + ' moves.');
ftime := GetSystemTime;
writeln('Finish Time : ' + ToStr(ftime));
rtime:= ftime - stime;
writeln('Total Run Time : ' + ToStr(rtime));
end.