C implementation of Tic-Tac-Toe in a single call to printf
21–30 of 85 posts
Re: C implementation of Tic-Tac-Toe in a single call to printf
#22This is just crazy and I love it From a description on the author's website[1] of a Doom clone written in 13k of JavaScript. > Until recently all content on this website was research, and while writing papers can be fun, sometimes you just need to blow off a little steam. I think more companies should allow for their employees to have some plain old fun with no strings attached on a regular basis. [1] https://nichola…
Nicholas Carlini's resume is crazy-insane and he's highly desirable, so of course Google Brain is going to lend him far more flexibility than Google Analytics would have with a recent college-hire, or at the other end of the supply/demand distribution: the working flexibility Amazon would afford a warehouse employee (if they aren't a contractor...).
Re: C implementation of Tic-Tac-Toe in a single call to printf
#23> %n takes a pointer and writes (!!) the number of bytes printed so far. > Okay, everyone probably knows this. Let's get a bit more advanced. Ok, but I didn't know about that. What's the use?
One use is aligning outputs: char *prefix = "example"; char *line1 = "line 1"; char *line2 = "line 2"; printf("%s: %n%s\n", prefix, &n, line1); printf("%*s%s\n", n, "", line2); will output example: line 1 line 2 That’s a bit more robust than using strlen(s)+2 , where you have to keep that magic constant 2 in sync with ": ". Moving ": " to a variable and using strlen(s)+strlen(separator) would fix that, though (at the…
strlen wouldn't even be an option if you were formatting something that's not a string e.g.
int n;
int prefix_num = 23;
char *line1 = "line 1";
char *line2 = "line 2";
printf("example %d: %n%s\n", prefix_num, &n, line1);
printf("%*s%s\n", n, "", line2);Re: C implementation of Tic-Tac-Toe in a single call to printf
#24> while(*d) printf(fmt, arg)
How's that a single call ?
Re: C implementation of Tic-Tac-Toe in a single call to printf
#25Re: C implementation of Tic-Tac-Toe in a single call to printf
#26I am afraid that the author has disqualified himself by publishing the source code before the judging of IOCCC 2020 is over. See catch 22 in the rules: "The judges STRONGLY prefer to not know who is submitting entries to the IOCCC."[1] Even the winners are asked not to publish the code until it is available on the IOCCC web site.[2] [1] https://ioccc.org/2020/rules.txt [2] Personal communication
‘Strongly prefer‘ != disqualification
Re: C implementation of Tic-Tac-Toe in a single call to printf
#27Earlier quoted context omitted.
Nah. Dennis Ritchie HATES him. Program like a pro with this one weird trick! You won't believe what happens! That's proper bait.
Hence advanced bait. printf() is called in a while loop, so it is hardly a single call.
Re: C implementation of Tic-Tac-Toe in a single call to printf
#28> in a single call to printf > while(*d) printf(fmt, arg) How's that a single call ?
syntactically it is. But it's not a very clear description. So how would you describe that single call location getting executed in a loop so everybody understands what is really meant? A single line of code is worse.
Re: C implementation of Tic-Tac-Toe in a single call to printf
#29Love the attempt the blindside the reader with funky formatting showing "%N".
A more subtle touch is that the #defines spell out NOUGHTs AnD CRoSSES.
Re: C implementation of Tic-Tac-Toe in a single call to printf
#30Earlier quoted context omitted.
One use is aligning outputs: char *prefix = "example"; char *line1 = "line 1"; char *line2 = "line 2"; printf("%s: %n%s\n", prefix, &n, line1); printf("%*s%s\n", n, "", line2); will output example: line 1 line 2 That’s a bit more robust than using strlen(s)+2 , where you have to keep that magic constant 2 in sync with ": ". Moving ": " to a variable and using strlen(s)+strlen(separator) would fix that, though (at the…
I'd never heard of %n, but I use printf's return value (the number of bytes written) for this kind of purpose, so n = printf("%s: ", prefix); printf("%s\n", line1); printf("%*s%s\n", n, " ", line2);