C Puzzle #2! "-1--2--3--4--5--6--7--8-"
Pages: [1]
|
|
Programming Help
|
superjer
superjer

2005 Mar 20 • 3742
|
This one I made up myself without ripping anyone off.
The following C program is 43 characters long and prints a particular string.
main(){printf("-1--2--3--4--5--6--7--8-");}
Can you write a program in 42 characters or less which does the same thing?
Assume you can use printf without any includes and ignore all warnings.
|
|
|
|
|
(Edited 2009 Jul 5 at 13:13)
2009 Jul 5 at 12:54
|
|
|
Down Rodeo
Cap'n Moth of the Firehouse


2007 Oct 19 • 5258
57,583 ₧
|
|
|
|
|
|
2009 Jul 6 at 10:09
|
|
|
Down Rodeo
Cap'n Moth of the Firehouse


2007 Oct 19 • 5258
57,583 ₧
|
|
|
|
|
|
(Edited 2009 Jul 8 at 13:25)
2009 Jul 8 at 13:24
|
|
|
superjer
superjer

2005 Mar 20 • 3742
|
Down Rodeo said: main(){puts("-1--2--3--4--5--6--7--8-");}
That is a good answer but it doesn't do exactly the same thing as the original program.
|
|
|
|
|
(Edited 2009 Jul 9 at 12:55)
2009 Jul 9 at 12:55
|
|
|
Jake?!

2008 Sep 2 • 196
34 ₧
|
superjer said: That is a good answer but it doesn't do exactly the same thing as the original program.
You should be more like the dick judge on American Idol, i.e.:
Your code is sloppy and lacks resonance Down Rodeo, I find myself wondering why I'm reading it at all. Although I was intrigued by it's apparently sassy attitude, it turned out to flat and pretentious. Oh and by the way, IT'S BLATANTLY WRONG AND DOES NOT DO THE EXACT SAME THING YOU PANDY FACKLER. Don't worry though, I'm sure you will find a programming job someday... say 1971..ish.
?!
|
|
|
|
|
(Edited 2009 Jul 9 at 21:53)
2009 Jul 9 at 21:51
|
|
|
Down Rodeo
Cap'n Moth of the Firehouse


2007 Oct 19 • 5258
57,583 ₧
|
Yes, helpfully puts() appends a newline. I forgot that :(
main(){int i=1;l:i<9?printf("-%d",i++);goto l;:}
doesn't work I think and is too long anyway.
main(){int i=1;while(i<9)printf("-%d-",i++);}
is shorter, probably works, still too long.
main(){int i=1;for(i;i<9;)printf("-%d-",i++);}
is quite smart I think, ought to work still, the thing with all these is I am hoping since all the bits are on one line the curlies are not needed which is true. Do I get any credit for trying?
Everyone stares when you walk in the room, they stare when you go....
|
|
|
|
|
(Edited 2009 Jul 10 at 09:36)
2009 Jul 10 at 09:24
|
|
|
superjer
superjer

2005 Mar 20 • 3742
|
Down Rodeo said: main(){int i=1;while(i<9)printf("-%d-",i++);}
is shorter, probably works, still too long.
That is 45 characters, but it does the right thing...
Down Rodeo said: main(){int i=1;for(i;i<9;)printf("-%d-",i++);}
is quite smart I think, ought to work still, the thing with all these is I am hoping since all the bits are on one line the curlies are not needed which is true.
You don't need curlies and you really don't need the extraneous i in your for. Change for(i;i<9;) to for(;i<9;) for starters.
Down Rodeo said: Do I get any credit for trying?
Sure! You get virtual kudos.
|
|
|
|
|
(Edited 2009 Jul 10 at 10:48)
2009 Jul 10 at 10:48
|
|
|
the_cloud_system
polly pushy pants

2008 Aug 1 • 2788
-6 ₧
|
no kudos for you
moo moo moo, moo.
|
|
|
|
|
2009 Jul 16 at 00:48
|
|
|
Down Rodeo
Cap'n Moth of the Firehouse


2007 Oct 19 • 5258
57,583 ₧
|
|
|
|
|
|
2010 Jan 16 at 09:41
|
|
|
stanlo
2010 Mar 19 • 1
|
code main(int a){for(;a-9;printf("-%d-",a++));}
?
|
|
|
|
|
2010 Mar 19 at 18:39
|
|
|
the_cloud_system
polly pushy pants

2008 Aug 1 • 2788
-6 ₧
|
yah its tech understandable...to a point
moo moo moo, moo.
|
|
|
|
|
2010 Mar 19 at 20:37
|
|
|
superjer
superjer

2005 Mar 20 • 3742
|
stanlo said: code main(int a){for(;a-9;printf("-%d-",a++));}
?
Looks good. You get a cookie!
(It is dependent on argc being exactly 1, though. Not a huge problem but still avoidable.)
|
|
|
|
|
(Edited 2010 Mar 20 at 18:55)
2010 Mar 20 at 18:50
|
|
|
|
Pages: [1]
|