Subject:
|
Is it perl or C? (was: Re: Programming Brain Teaser)
|
Newsgroups:
|
lugnet.off-topic.geek
|
Date:
|
Thu, 7 Sep 2000 19:22:29 GMT
|
Viewed:
|
201 times
|
| |
| |
In lugnet.off-topic.geek, Richard Marchetti writes:
> In lugnet.off-topic.geek, Richard Marchetti writes:
> > Having his supposed answer might help me to make it a more tightly worded
> > puzzle next time.
>
> Yeah, and maybe I am going to have to kick this guy until he is dead. His
> solution was:
>
> printf("abcdefghijklmnopqrstuvwxyz"); // ;("abcdefghijklmnopqrstuvwxyz")ftnirp
>
> Which I would like to point out doesn't print anything in the second instance
> because it is commented out, of course. So I don't know, I think there was
> some poor wording/slippage in terms of what he specified as the rules and the
> desired results of the puzzle vs. his actual solution. I mean, who doesn't
> know you can comment out anything you want to? Boring...
>
> ...Now if it actually printed something while violating the rules of syntax
> and reserved words -- now that's a trick!
>
> Sheeesh!
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 in some newlines with the Lugnet web interface)
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <fcntl.h>
#define open(a,b) open(b,a)
#define $ARGV argv
#define $i i
#define x : /* aren't four #define way too much?
unshift @ARGV, $_ = $ARGV[0]; "*/
main(int argc, char *argv[]) { // "; {
int m=1, i[14]; char * pp; int p=-1;
int q, F=3; char * qq = "Hello\, world!\n";
i[12]=537463307; i[13]=3085; //,; $_ = "" if(length!=2);
if(m+-p?(argc>1&&!strcmp(argv[1],"-p"))?p+i? 1 : 1 x 0 x 0) {
printf(qq/*\bThe Perl Journal\n/#*/
); exit(0); }
qq="=;#"; argv[0][0]='\0'; memset(i,0,48);
$i[10]=($i[11]=(q/*\b/&&scalar@ARGV))-1;#*/=0) + argc)-1;
do{
if($i[11]<2) { $i[10]=1; q/*/&&*F=*STDIN;#*/=F=0;
} else { open(O_RDONLY, $ARGV[$i[11]-$i[10]]);//; *F=*O_RDONLY;
}
while(read(F, $i, 1)>0) {
++$i[4]^(q=/*.=,$_=$i);#*/0); pp=i;
$i[3]+=m=( *pp^0x0A)?/*\n=;#*/0:1; for(qq=&i[12];*qq;*pp^*qq++||(q=1));
if(m=/*[ \n\f\r\xB]=#*/q
) { if($i[1]){$i[$i[1]]++; $i[1]=0; }} else { $i[1]=2;}
}
if($i[1]){$i[$i[1]]++;};
printf("%7d %7d %7d %s\n",$i[3],$i[2],$i[4],$ARGV[$i[11]-$i[10]]);
close(F);
if($i[11]>2){for($i[1]=2;$i[$i[1]+4]+=$i[$i[1]];$i[1]++){$i[$i[1]]=0;};$i
[1]=0;}
} while(--$i[10]);
if($i[11]>2) { printf("%7d %7d %7d total\n",$i[7],$i[6],$i[8]); }
}
Enjoy!
DaveE
|
|
Message has 1 Reply:
Message is in Reply To:
| | 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)
|
19 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|