Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Hans

Have you made any small but cool C programs?

This topic is 6912 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Have you made C programs that are less than 10 lines (80 chars/line) and they print out something nice? I've seen a couple but I'd like to see more! Here's one I did: int a[862],p[]={0,2,0,-2,0},e,d,o=2,n;main(c){scanf("%d",&c);srand(c); for(;e<40;e++){a[e]=6;a[e+820]=6;a[e/2*41]=6;a[e/2*41+40]=6;}a[2]=5;while(c- 42){for(e=0;e<2;e++){o+=p[d]/2+p[d+1]/2*41;a[o]=d+1;}m:d=(d-1+rand()%3)&3; n=o+p[d]+p[d+1]*41;if(a[n]){if(e++==99){d=(a[o]+1)&3;o+=p[d]+p[d+1]*41;if( a[o]-5){e=2;goto m;}else c=42;}else goto m;}}o=776;a[817]=8;for(;a[o]-5;o+= p[d]/2+p[d+1]/2*41){d=(a[o]+1)&3;a[o]=8;o+=p[d]/2+p[d+1]/2*41;a[o]=8;} for(;c<821;c++){n=a[c];printf(c%41?"%c":"%c\n",(!n?'#':n&8?'.':' '));}} It creates a maze and also solves it. (okay the code is quite long and easy to understand but hey it's my first try). -Hans Edited by - Hans on 5/14/00 9:29:23 AM

Share this post


Link to post
Share on other sites
Advertisement
Hey that's cool. I had to add a couple of #includes and fix the place on the last line where the forum wrecked your array index, but it worked!

I *did NOT* write the following, I found it on the net somewhere. You may have seen it.

Arghh...

Oh crap, I can't get the formatting to work on this forum, even with the <pre> tags. Download what I'm trying to show you from here. Amazingly, there are 2 examples of code that produce the same output (12days.c and xmas.c) The other one (wc.c) counts the lines, words, and characters in a file (syntax for executable: wc < autoexec.bat).

the Gent



Edited by - An Irritable Gent on May 14, 2000 10:51:18 AM

Edited by - An Irritable Gent on May 14, 2000 10:51:52 AM

Share this post


Link to post
Share on other sites
Along these lines, look at the past winners for the International Obfuscated C Code Competition (www.ioccc.org).

Share this post


Link to post
Share on other sites
Adding srand made it a little more interesting. Nothing against displaying the same maze over and over, but I do like a little randomness!

Share this post


Link to post
Share on other sites
Oh, I forgot to mention, this is actually a lot more than 10 lines of code. Just because it was literaly 10 lines, does not mean that it was 10 lines of code. Basically, every semicolon is treated as a new line. (There are exceptions,e.g. a for loop is generally consided one line, variable declartions are not a line of code unless you assign an initial value, etc...)

Share this post


Link to post
Share on other sites
nice program
but ioccc is totally different, i tried to participate in it last year, unfortunately my code wasn''t that obfuscated at all.

- pouya

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!