I rewrote some of your program and tested it out. I also corrected your
if statement to compute the equality of the 3 words against the 1. I also added in totals for how many times it was tried and how many succeeded.
[{Solve the cryptogram LOCK
CANAL
CACHE
-----
HIDDEN
found on Programmer's Heaven that somebody wanted some help with
on this date 2012-Aug-25
revised by Carl W. Skipworth Rev Date 2012-Aug-28 }
program Hidden;
const
nz : integer = ord( '0' ); { number zero( in character form ) }
ten = 10; { worth ten }
oh = 100; { worth one hundred }
ot = 1000; { worth one thousand }
tt = 10000; { worth ten thousand }
ht = 100000; { worth hundred thousand }
type
str10 = string[10];
var
l, o, c, k, a, n, h, e, i, d : integer;
s, outstr : str10;
fout : text;
attempts : longint;
successes : integer;
procedure TryOne;
begin
Inc( attempts );
l := ord( outstr[ 1] ) - nz;
o := ord( outstr[ 2] ) - nz;
c := ord( outstr[ 3] ) - nz;
k := ord( outstr[ 4] ) - nz;
a := ord( outstr[ 5] ) - nz;
n := ord( outstr[ 6] ) - nz;
h := ord( outstr[ 7] ) - nz;
e := ord( outstr[ 8] ) - nz;
i := ord( outstr[ 9] ) - nz;
d := ord( outstr[10] ) - nz;
if l * ot + o * oh + c * ten + k + { 1st word }
c * tt + a * ot + n * oh + a * ten + l + { 2nd word }
c * tt + a * ot + c * oh + h * ten + e = { 3rd word }
h * ht + i * tt + d * ot + d * oh + e * ten + n then begin
writeln( fout, ' l = ',l );
writeln( fout, ' o = ',o );
writeln( fout, ' c = ',c );
writeln( fout, ' k = ',k );
writeln( fout, ' a = ',a );
writeln( fout, ' n = ',n );
writeln( fout, ' h = ',h );
writeln( fout, ' e = ',e );
writeln( fout, ' i = ',i );
writeln( fout, ' d = ',d );
writeln( fout );
writeln( fout,' ',l,o,c,k );
writeln( fout,' ',c,a,n,a,l );
writeln( fout,' ',c,a,c,h,e );
writeln( fout,' --------' );
writeln( fout,' ',h,i,d,d,e,n );
writeln( fout);
writeln;
writeln( ' ',l,o,c,k );
writeln( ' ',c,a,n,a,l );
writeln( ' ',c,a,c,h,e );
writeln( ' --------' );
writeln( ' ', h,i,d,d,e,n );
Inc( successes )
end
end;
procedure Permute_it ( s : str10 );
var
ss : str10;
i, len : integer;
begin
len := length( s );
if len = 0 then
TryOne
else
for i := 1 to len do begin
outstr := outstr + s[i];
ss := s;
delete( ss, i, 1 );
Permute_it( ss );
Delete( outstr, length( outstr ), 1 )
end
end;
begin
assign( fout, 'B:\HIDDEN.TXT');
rewrite( fout );
attempts := 0;
successes := 0;
outstr := '';
s := '0123456789';
Permute_it( s );
writeln( fout, ' attempts = ', attempts, ' successes = ', successes );
writeln( ' attempts = ', attempts, ' successes = ', successes );
close( fout )
end./code]