home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18571 < prev    next >
Encoding:
Text File  |  1992-12-18  |  3.2 KB  |  84 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!evolving.com!manus
  3. From: manus@evolving.com (Manus Hand)
  4. Subject: Re: Another C palindrome puzzle
  5. Message-ID: <1992Dec17.223414.164558@evolving.com>
  6. Date: Thu, 17 Dec 1992 22:34:14 GMT
  7. References: <9234503.17437@mulga.cs.mu.OZ.AU>
  8. Organization: Evolving Systems, Inc.
  9. X-Newsreader: Tin 1.1 PL4
  10. Lines: 72
  11.  
  12. fjh@munta.cs.mu.OZ.AU  (Fergus James Henderson) writes:
  13. >
  14. >   Next challenge: Write a palindromic "hello world" program in C without
  15. >   using comments, #if, or #ifdef.  I think it should be possible.
  16.  
  17. Challenge accepted!  As Henderson did, I assert that new-line characters are
  18. not significant when determining palindromism (palindromicity?).  So here's
  19. a program that fits the bill, as short as I can make it.  Enjoy.
  20.  
  21.                         main(){
  22.                         #define amgarp
  23.                         #pragma}
  24.                         puts("Hello world");amgarp
  25.                         #pragma;)"dlrow olleH"(stup
  26.                         }amgarp
  27.                         #pragma enifed#{)(niam
  28.  
  29. It is trivial to make the program #include <stdio.h> and prototype its main()
  30. function (for purists like me).
  31.  
  32. The program may not be strict ANSI (I don't know what constraints are placed on
  33. #pragma directive syntax by the standard), so here is a much earlier version
  34. of my solution, before being shortened again and again.  This should keep the
  35. even the most nit-picky preprocessor happy as a clam:
  36.  
  37.                         #define enifed
  38.                         #define fednu
  39.                         #
  40.                         main() fednu enifed
  41.                         #
  42.                         fednu fednu
  43.                         #
  44.                         { fednu enifed
  45.                         #
  46.                         fednu fednu
  47.                         #define define }
  48.                         puts("Hello world"); fednu enifed
  49.                         #define undef ;)"dlrow olleH"(stup
  50.                         } enifed enifed
  51.                         #undef undef
  52.                         #define undef {
  53.                         #undef undef
  54.                         #define undef )(niam
  55.                         #undef enifed
  56.                         #define enifed#
  57.  
  58. I also came up with a "mirror" palindrome solution (in which the characters
  59. "(", "[", and "{" are reflected in the palindrome by ")", "]", and "}").  This
  60. is given below:
  61.  
  62.                     #define enifed
  63.                     main()enifed enifed
  64.                     #
  65.                     {;
  66.                     #define stup;
  67.                     puts(("dlrow olleH","Hello world"))stup
  68.                     ;puts enifed
  69.                     #
  70.                     ;}
  71.                     #define define()niamdefine enifed#
  72.  
  73. Now I suppose I have to come up with the NEXT challenge.  Okaaaayyyy....
  74. how about a palindromic "Hello world" program, with no comments, #if's,
  75. #ifdef's, <<<OR #define's!>>>
  76.  
  77. Keep me posted!
  78.  
  79. -- 
  80. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  81. Name:           Manus J. Hand (The Lobsterman)     >\          Phone:   busy
  82. Quest:          Evolving Systems, Inc.             =:(((<      Home:    here
  83. Favorite color: lavendar                           >/          E-mail:  yes
  84.