[Gllug] "A man, a plan, a canal, Panama!"

Stig Brautaset stigbrau at online.no
Sat Sep 22 23:30:53 UTC 2001


Hello,

I did mention an obfuscated C program designed to find palindromes
(palindromes are words or phrases that are the same backwords and
forwards, disregarding punctuation; i.e. the word "anna" or the rather
famous phrase in the subjectline). Here it is, as found on comp.lang.c.
Comments at top and bottom is inserted by me.

I'll leave it as an exercise for the reader to find the bug :)

/* file starts here */

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define p void
#define   a sizeof
#define      l char
#define        i return
#define          n int
#define           d size_t
#define            r if
#define             o while
#define              m else
#define              e for
#define              ob putchar
#define              fu strlen
#define             sc isalpha
#define             at tolower
#define            ed fgets
#define          cp printf
#define        ro strchr
#define     gr main
#define am stdin
n c(l*s){n k=
0;r(s){d x
=fu (s)
;r(x>1)
{l*t=s,
*u=s+x-
1;k=1;o
(k&&t<u
){r(sc(
*t)){r(
sc(*u))

    {r(at(
   *t)!=at(
  *u)    ){k
 =0;      }m{
++t;--u;}}m{--
u;}}m{++t;}}}}
i k        ;}n
gr(        p){
l b        [01
<<1        <<1

<<1
<<1
<<1
<<1
<<1
<<1
<<1
],*
z,*s=" adeil"
"mnoprst.\n";

n f[]={00,01<<1
<<1,(1<<1<<1<<1
      )|(
      1<<
      1)|
      1},
      v[]
      ={0
,(1<<1<<1)|(1<<
1)|1,1<<1<<1<<1


,(1         <<1
<<01        <<1
)|(01       <<1
<<1 )}      ,q[
]={  (1     <<1
)&1   ,1    <<1
>>1    ,1   >>1
,(1     <<  1<<
1<<      1) |1,
1<<       01<<1


>>1>>1,(1<<1
<<1       )|(
1<<        1>>
1),         1<<
1<<         1,(
1<<         1<<
1)|         (01
<<1        )|1
,01       <<1
,(1<<1<<1<<1


)|(1<<01),1
<<1      <<1
<<1       ,(1
<<1       <<1
)|1      <<1
,(1   <<1
)|1,(1<<
1<<   1<<
1)|    (01
<<1     <<1
)|1      ,(1
<<1       <<1


   <<1)|(1<<
 1<<       1)|
(01         <<1
)};         d y
;o(         ed(
b,a         (b)
,am         )){
{z=         ro(
 b,1        *1*
   '\n');}if(

z){          *z=
00;}        {cp(
"%s",      b);}e
(y=0;1    *y<a f
/a( 1[f  ]); y++
)ob  (y[f][  s])
;r(   !c(b   ))e
(y=    0;    y<a
v/a          1[v
];y          ++)


ob(01*y[v][s]);e
(y=0/1*1/1<<1<<1
<<1
;y<
a q
/a 1[q]
;y++)ob
(y[
q][
s])
;}i 0>>1<<0>>1<<
1*1/(1<<1<<01);}

/* file ends here */

Regards,
Stig

-- 
brautaset.org
Registered Linux User 107343

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list