Re: C Contest...
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 03/21/05
- Next message: Francis Glassborow: "Re: Problem with map::iterator?"
- Previous message: Anthony Borla: "Re: Problem with map::iterator?"
- In reply to:(deleted message) Aaron: "C Contest..."
- Next in thread: Mark P: "Re: C Contest..."
- Reply: Mark P: "Re: C Contest..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 21 Mar 2005 17:01:00 -0500 (EST)
On Thu, 17 Mar 2005, Aaron wrote:
>
> A long time ago my brother and I had a contest to see who could write the
> smallest card shuffler. I won with 316 bytes. (keystrokes). Below is the
> source.
>
> Can anybody beat it?
Given that your "shuffling" algorithm produces the same output each
time it's run --- and not a very "random-looking" one at that --- and
even if you seed the RNG differently, you still get only 52 different
outcomes, I think it's perfectly reasonable to submit
#include <stdio.h>
int d[52];int main(){char*c[]={"Ace","2","3","4","5","6","7","8","9",
"10","Jack","Queen","King","Diamonds","Spades","Hearts","Clubs"},i,j;
for(i=0;i<52;++i)d[i]=i*9%52,printf("%s of %s\n",c[i*9%13],c[i*9/13%4
+13]);return 0;}
247 characters, counting the three extraneous newlines.
The fun of C golf is in doing /interesting/ things, though!
Make a 316-character C program that actually randomizes an array,
instead of just printing long strings of text, and you've got
something.
-Arthur
- Next message: Francis Glassborow: "Re: Problem with map::iterator?"
- Previous message: Anthony Borla: "Re: Problem with map::iterator?"
- In reply to:(deleted message) Aaron: "C Contest..."
- Next in thread: Mark P: "Re: C Contest..."
- Reply: Mark P: "Re: C Contest..."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|