home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!csn!evolving.com!manus
- From: manus@evolving.com (Manus Hand)
- Subject: Re: Another C palindrome puzzle
- Message-ID: <1992Dec17.223414.164558@evolving.com>
- Date: Thu, 17 Dec 1992 22:34:14 GMT
- References: <9234503.17437@mulga.cs.mu.OZ.AU>
- Organization: Evolving Systems, Inc.
- X-Newsreader: Tin 1.1 PL4
- Lines: 72
-
- fjh@munta.cs.mu.OZ.AU (Fergus James Henderson) writes:
- >
- > Next challenge: Write a palindromic "hello world" program in C without
- > using comments, #if, or #ifdef. I think it should be possible.
-
- Challenge accepted! As Henderson did, I assert that new-line characters are
- not significant when determining palindromism (palindromicity?). So here's
- a program that fits the bill, as short as I can make it. Enjoy.
-
- main(){
- #define amgarp
- #pragma}
- puts("Hello world");amgarp
- #pragma;)"dlrow olleH"(stup
- }amgarp
- #pragma enifed#{)(niam
-
- It is trivial to make the program #include <stdio.h> and prototype its main()
- function (for purists like me).
-
- The program may not be strict ANSI (I don't know what constraints are placed on
- #pragma directive syntax by the standard), so here is a much earlier version
- of my solution, before being shortened again and again. This should keep the
- even the most nit-picky preprocessor happy as a clam:
-
- #define enifed
- #define fednu
- #
- main() fednu enifed
- #
- fednu fednu
- #
- { fednu enifed
- #
- fednu fednu
- #define define }
- puts("Hello world"); fednu enifed
- #define undef ;)"dlrow olleH"(stup
- } enifed enifed
- #undef undef
- #define undef {
- #undef undef
- #define undef )(niam
- #undef enifed
- #define enifed#
-
- I also came up with a "mirror" palindrome solution (in which the characters
- "(", "[", and "{" are reflected in the palindrome by ")", "]", and "}"). This
- is given below:
-
- #define enifed
- main()enifed enifed
- #
- {;
- #define stup;
- puts(("dlrow olleH","Hello world"))stup
- ;puts enifed
- #
- ;}
- #define define()niamdefine enifed#
-
- Now I suppose I have to come up with the NEXT challenge. Okaaaayyyy....
- how about a palindromic "Hello world" program, with no comments, #if's,
- #ifdef's, <<<OR #define's!>>>
-
- Keep me posted!
-
- --
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- Name: Manus J. Hand (The Lobsterman) >\ Phone: busy
- Quest: Evolving Systems, Inc. =:(((< Home: here
- Favorite color: lavendar >/ E-mail: yes
-