Program Penul;



USES

    crt;



VAR

  d,c,b,a,s1,s0:Integer;

  d1,c1,b1,a1:Integer;



  Leido:Char;



procedure despliega(d,c,b,a:Integer);

VAR

   N3,N2,N1,N0:Boolean;



PROCEDURE al;

BEGIN

     gotoxy(1,1);

     Write('----------');

END;



PROCEDURE bl;

VAR

   y:Integer;

BEGIN

     FOR y:=2 TO 5 DO

     BEGIN

          gotoxy(10,y);

          Write('|');

     END;

END;



PROCEDURE cl;

VAR

   y:Integer;

BEGIN

     FOR y:=6 TO 9 DO

     BEGIN

          gotoxy(10,y);

          Write('|');

     END;

END;



PROCEDURE dl;

BEGIN

     gotoxy(1,10);

     Write('----------');

END;



PROCEDURE el;

VAR

   y:Integer;

BEGIN

     FOR y:=6 TO 9 DO

     BEGIN

          gotoxy(1,y);

          Write('|');

     END;

END;



PROCEDURE fl;

VAR

   y:Integer;

BEGIN

     FOR y:=2 TO 5 DO

     BEGIN

          gotoxy(1,y);

          Write('|');

     END;

END;



PROCEDURE gl;

BEGIN

     gotoxy(1,5);

     Write('----------');

END;



BEGIN

   IF d=1 Then N3:=True ELSE N3:=False;

   IF c=1 Then N2:=True ELSE N2:=False;

   IF b=1 Then N1:=True ELSE N1:=False;

   IF a=1 Then N0:=True ELSE N0:=False;



   BEGIN



     IF N1 THEN

        IF N0 THEN

           IF (N3 or N2) THEN al  ELSE

        ELSE

            al

     ELSE

        IF N0 THEN

           al

        ELSE

            IF (N3 or N2) THEN al ELSE;





     IF (N1 or not(N2)) THEN  bl  ELSE ;





     IF N1 THEN

        cl

     ELSE

        IF N0 THEN

           IF (N2 or N3) THEN cl ELSE

        ELSE

            cl;





     IF N1 THEN

        IF N0 THEN

           IF (N2 or N3) THEN dl ELSE

        ELSE

            IF not(N2 or N3) THEN  dl ELSE

     ELSE

        IF N0 THEN

           IF not(N3) THEN  dl  ELSE

        ELSE

            IF (N2 or N3) THEN  dl ELSE;





     IF N1 THEN

        IF N0 THEN

           IF (N2 or N3) THEN  el ELSE

        ELSE

     ELSE

        IF N0 THEN

            el

        ELSE;





     IF N1 THEN

        IF N0 THEN

           fl

        ELSE

     ELSE

        IF N0 THEN

           IF (N2 or N3) THEN  fl  ELSE

        ELSE

            IF (N2 or N3) THEN fl ELSE;





     IF N1 THEN

        IF N0 THEN

            gl

        ELSE

            IF not(N2 or N3) THEN  gl ELSE

     ELSE

        IF N0 THEN

           gl

        ELSE

            IF (N2 or N3) THEN gl;



     ReadLn;

   END

END;





Procedure identifica(d,c,b,a:Integer);

BEGIN

     IF ( ((d and 1)=0) and ((c and 1)=0) and ((b and 1)=0) and ((a and 1)=0) ) THEN

        WriteLn('0');

     IF ( ((d and 1)=0) and ((c and 1)=0) and ((b and 1)=0) and ((a and 1)=1) ) THEN

        WriteLn('1');

     IF ( ((d and 1)=0) and ((c and 1)=0) and ((b and 1)=1) and ((a and 1)=0) ) THEN

        WriteLn('2');

     IF ( ((d and 1)=0) and ((c and 1)=0) and ((b and 1)=1) and ((a and 1)=1) ) THEN

        WriteLn('3');

     IF ( ((d and 1)=0) and ((c and 1)=1) and ((b and 1)=0) and ((a and 1)=0) ) THEN

        WriteLn('4');

     IF ( ((d and 1)=0) and ((c and 1)=1) and ((b and 1)=0) and ((a and 1)=1) ) THEN

        WriteLn('5');

     IF ( ((d and 1)=0) and ((c and 1)=1) and ((b and 1)=1) and ((a and 1)=0) ) THEN

        WriteLn('6');

     IF ( ((d and 1)=0) and ((c and 1)=1) and ((b and 1)=1) and ((a and 1)=1) ) THEN

        WriteLn('7');

     IF ( ((d and 1)=1) and ((c and 1)=0) and ((b and 1)=0) and ((a and 1)=0) ) THEN

        WriteLn('8');

     IF ( ((d and 1)=1) and ((c and 1)=0) and ((b and 1)=0) and ((a and 1)=1) ) THEN

        WriteLn('9');

END;



BEGIN

     a:=0;

     b:=0;

     c:=0;

     d:=0;

     s0:=0;

     s1:=0;



Repeat

      clrscr;

      despliega(d,c,b,a);

{*      identifica(d,c,b,a);

      writeln((s1 and 1):3,(s0 and 1):3); *}



      IF  ( not(a) and not(b) and not(c) and not(d) and not(s1) and (s0) )

          OR ( not(a) and not(b) and (d) and not(s1) and not(s0) )

          OR ( (a) and not(b) and (c) and (s1) and not(s0) )

          OR ( (a) and (b) and (c) and not(s1) and not(s0) )

          OR ( not(a) and (b) and (c) and (s1) and not(s0) )

          OR ( (a) and not(c) and (d) and not(s1) and (s0) ) = 1

      Then d1:=1 Else d1:=0;



      IF  ( not(a) and not(b) and (c) and not(s0) )

          OR ( not(a) and not(c) and (d) and not(s1) and (s0) )

          OR ( (a) and not(b) and not(c) and not(d) and (s1) and not(s0) )

          OR ( (a) and not(b) and (c) and not(s1) )

          OR ( (a) and (b) and not(c) and not(d) and not(s0) )

          OR ( (a) and (b) and (c) and not(s1) and (s0) )

          OR ( not(a) and (b) and not(c) and not(d) and (s1) and not(s0) )

          OR ( not(a) and (b) and (c) and not(s1) ) = 1

      Then c1:=1 Else c1:=0;



      IF  ( not(a) and not(b) and not(c) and not(d) and (s1) and not(s0) )

          OR ( not(a) and not(b) and (c) and not(d) and (s1 xor s0) )

          OR ( not(a) and not(b) and (d) and not(s1) and (s0) )

          OR ( (a) and not(b) and not(d) and not(s1) and not(s0) )

          OR ( (a) and not(b) and (d) and (s1) and not(s0) )

          OR ( (a) and (b) and not(c) and (s1 xor s0) )

          OR ( (a) and (b) and (c) and not(s1) and (s0) )

          OR ( not(a) and (b) and not(s1) and not(s0) ) = 1

      Then b1:=1 Else b1:=0;



      IF  ( not(a) and 1 )

          OR ( (a) and (s1) and (s0) ) = 1

      Then a1:=1 Else a1:=0;



      a:=a1;

      b:=b1;

      c:=c1;

      d:=d1;



      Leido:=Upcase(ReadKey);



      IF Leido='Q' THEN

         IF (s1 and 1) = 1 Then s1:=0

            ELSE s1:=1;



      IF Leido='P' THEN

         IF (s0 and 1) = 1 Then s0:=0

            ELSE s0:=1;



UNTIL(leido='S');

END.





    Source: geocities.com/v.iniestra/apuntes/dis_log

               ( geocities.com/v.iniestra/apuntes)                   ( geocities.com/v.iniestra)