| | Programming Brain Teaser
|
|
Hey Y'all: Someone posed the following teaser to me, and I admit that it has stumped me completely. It has even stumped my programmer buddies (which creates doubt in my mind that there IS actually a solution to the puzzle). The question was posed (...) (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) it doesn't have to actually produce anything, right? try this: perl -e 'print ,"lalal", tnirp' e- lrep :) I seem to recall some JAPH's code that would actually do things and would still qualify... but I can't find it yet... :) Dan (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) Does the code need to compile in all of those, or just some of them? It's really easy in perl. :) Does it have to compile by itself, or can it be part of a larger program? The former is more difficult in C/C++... Also, what qualifies as a (...) (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) #include <stdio.h> #include <stdlib.h> #include <time.h> void rof(void) {}; void main(){ int C; C = 0 // line below ; for (C;C;C) rof; // Ok so its lame } // Should be valid in perl too, but I am not sure. Just an off the cuff answer. DaveG (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) And a good one. Thanks for the replies. I think I am beginning to see some ways into it that I hadn't thought of. The way I was understanding the puzzle (and you know that people have a tendency to explain things quite poorly AND I tried to (...) (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) thx (...) I may be dense too, just thought of it a ; on a line alone fits exactly the definition as stated. Going to sleep now before I think of more [/:-) DaveG (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) Is ';' a "statement", though? (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) Well the obvious answer is ";", but that's a bit too simple. I can't think of anything else that doesn't involve several variable and/or function definitions elsewhere. (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) Yeah, and maybe I am going to have to kick this guy until he is dead. His solution was: printf("abcdefghijkl...tuvwxyz"); // ;("abcdefghijklmnopq...yz")ftnirp Which I would like to point out doesn't print anything in the second instance (...) (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Is it perl or C? (was: Re: Programming Brain Teaser)
|
|
(...) Here's one that's MUCH better-- 'course most of you may have seen this already... someone made code equivalent to UNIX's wc command that can be compiled and run the exact same in perl and C... this one was really clever: (Grrr, it's gonna put (...) (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
In lugnet.off-topic.geek, Richard Marchetti writes: <snip> (...) <snip> Yikes!!! Programmers are way too serious. I have heard of not being able to take a joke, but come on... :-) Jude (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) 'Course, that's not legal C.... (24 years ago, 7-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) Not even legal Perl and he did say Perl. Only works in C++ or in a C with C++ extentions. Kick him twice as much. And (MattM) you may be right that the ; alone is to taking a liberty with the term statement. DaveG (24 years ago, 8-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) ;("abcdefghijklmnopq...yz")ftnirp (...) 'Course, if ';' doesn't count as a statement, it makes it much more difficult, since most commands end with a ';', and therefore have to start with one as well if they're to be read in backwards-- making (...) (24 years ago, 8-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) Good one, works in perl, C, and C++ You win in my opinion. (...) What a nasty addition to the problem. Gonna have to think about it... DaveG (24 years ago, 8-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) Yeah, I thought of that one, but I'm not sure it counts as a statement. In perl, of course, it's a comment. And in C/C++, it's a preprocessor directive.... (...) Well, #define thisisnotapalindrome enifed# :) (24 years ago, 8-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Programming Brain Teaser
|
|
(...) You got it right again you punk<grin>, Page 616:Programming Perl O'Reilly: Statement- A *command* to the computer about what to do next....Not to be confused with a *declararation* which doesn't tell the computer to do anything, but just learn (...) (24 years ago, 8-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Is it perl or C? (was: Re: Programming Brain Teaser)
|
|
When looking at this, I can't believe I actually wanted to learn how to program ^-^ I thought it was much more simple, like AppleScript or the POV-ray scene description language. --Tobias David Eaton wrote: <SNIP> (...) (24 years ago, 13-Sep-00, to lugnet.off-topic.geek)
|
|
| | Re: Is it perl or C? (was: Re: Programming Brain Teaser)
|
|
(...) Well, this is an example of horrific code, because it was purposely written so that it would parse, compile, and run in two different languages ... actual C code or Perl code is usually much nicer to look at and understand. BUT, let it be said (...) (24 years ago, 13-Sep-00, to lugnet.off-topic.geek)
|