Oxi allh perl

Christos Ricudis ricudis at komodino.itc.auth.gr
Tue Jul 11 14:12:08 EEST 2006


Nikolaos Korkakakis wrote:
> Re paidia ELEOS pia me thn perl
>
> ka8e 3 kai ligo petate mia sponta gia thn perl, ti kalh glwssa ti 
> wraia pou einai poso apodotikh einai kai loipes mpourdes. Eleos kai 
> siga thn glwssa. H oTCL einai apeirws kaluterh kai sou dinei safws 
> perissoteres programmatistikes dunatothtes efoson sundiazete me thn 
> tk. Enw h perl ...

SIGA mwre :

#!perl
#
# Disclaimer : I have only proved this code correct (*), not acutally 
tested it.
# (*) for simplicity, I have ommited some minor irrelevant issues 
involving infinity
#
# I/O tape
$tape="00101001110101010010H";
# transitions table
# "$transitions[]="state,read,write,movement,new state";
$transitions[0]="0,0,1,r,0";
$transitions[1]="0,1,0,r,0";
$transitions[2]="0,H,H,l,1";
#
$halt=0;
$curstate=0;
$curpos=0;
while ($halt==0) {
   $match=0;
   foreach $i (@transitions) {
      ($state,$read,$write,$movement,$newstate)=split(/,/,$i);
      if (($state==$curstate) && ($read eq substr($tape,$curpos,1))) {
         $match=1;
         $curstate=$newstate;
         substr($tape,$curpos,1)=$write;
         if ($movement=="r") {
               $curpos++;
         } elsif ($movement=="l") {
               $curpos--;
         }
         break;                                                }
   }
   if ($match==0) {
       print "$tape\n";
       $halt=1;
   }
}

Twra to mono pou exeis na kaneis einai na ry8miseis swsta to $tape kai 
to $transitions[], kai na ftiakseis enan TCL interpreter.

-- 
Christos Ricudis				ricudis at itc.auth.gr
Systems Administrator				+30-2310-998656
IT Support Center
Aristotle University of Thessaloniki, GREECE




More information about the Linux-greek-users mailing list