1 Replies - 3504 Views - Last Post: 06 September 2012 - 04:31 AM Rate Topic: -----

#1 repmeer  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-August 12

Getting Runtime error 2 in Pascal Program

Posted 26 August 2012 - 03:55 AM

I trying to solve this puzzle:

LOCK + CANAL + CACHE = HIDDEN

Each letter represents a number from 0 to 9. There is only one solution.

I have found some code somewhere else to solve a problem like these and made some modifications but when i run the program i get a runtime error 2. The code is written in Pascal.
Can someone tell what i'm doing wrong? I have very few programming experience.

program Hidden;
 
{Solve the cryptogram   LOCK
                       CANAL
                       CACHE
                       -----
                      HIDDEN}
 
var l,o,c,k,a,n,h,e,i,d  :longint;
    s,outstr :string;
    fout :text;
 
procedure TryOne;
          var x,y :longint;
          begin
          l:=ord(outstr[0])-48;
          o:=ord(outstr[1])-48;
          c:=ord(outstr[2])-48;
          k:=ord(outstr[3])-48;
          a:=ord(outstr[4])-48;
          n:=ord(outstr[5])-48;
          h:=ord(outstr[6])-48;
          e:=ord(outstr[7])-48;
          i:=ord(outstr[8])-48;
          d:=ord(outstr[9])-48;
          if 1001*l + 200*o + 20110*c + k + 2010*a + 100*n + 20*h + e
               = 100000*h + 10000*i + 1100*d + 10*e + n
          then begin
             assign(fout,'HIDDEN.TXT'); append(fout);
             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('   ',   l,o,c,k);
             writeln('   ',  c,a,n,a,l);
             writeln('   ',  c,a,c,h,e);
             writeln('--------');
             writeln(h,i,d,d,e,n);
             close(fout);
             end;
          end;
 
procedure Permute_it(s :string);
          var ss    :string;
              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
outstr:='';
s:='0123456789';
Permute_it(s);
end.


Is This A Good Question/Topic? 0
  • +

Replies To: Getting Runtime error 2 in Pascal Program

#2 turboscrew  Icon User is offline

  • D.I.C Addict

Reputation: 100
  • View blog
  • Posts: 644
  • Joined: 03-April 12

Re: Getting Runtime error 2 in Pascal Program

Posted 06 September 2012 - 04:31 AM

What kind of Pascal is this?
I have used Pascal some decades ago, but this doesn't look familiar.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1