But it's actually a lot more clever than that.
I feel like this would be a lot more impressive if it was written in simple and clear C since then you'd see that there really isn't any tic-tac-toe logic being explicitly implemented the way you'd expect.
https://gist.github.com/hugomg/73e91ebca7ced3c5c6f955e9e830b...
E.g.
/usr/src/cmd/sh/mac.h:
#define IF if(
#define THEN ){
#define ELSE } else {
#define ELIF } else if (
#define FI ;}
#define BEGIN {
#define END }
#define SWITCH switch(
#define IN ){
#define ENDSW }
#define FOR for(
#define WHILE while(
[1] https://research.swtch.com/shmacroOne of my favourite accidental features in Rust is that macros are so annoying and cryptic to write that people think twice before abusing them.
[1] https://ioccc.org/2020/rules.txt [2] Personal communication
https://www.usenix.org/conference/usenixsecurity15/technical....
Very interesting. Roughly, that the existence of Turing-complete functions within programs creates a fundamental vulnerability that even rigid control over the control flow of a program cannot avoid.
> Okay, everyone probably knows this. Let's get a bit more advanced.
Ok, but I didn't know about that. What's the use?
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 price of speed, unless you’ve a compiler that optimizes that away)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); n = printf("%s: ", prefix);
printf("%s\n", line1);
printf("%*s%s\n", n, " ", line2);And we did something with it involving string translations. Since we didn't control the translated format string we couldn't just count the characters in the source code.
But it's been a really long time and I don't recall the details.
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.
Maybe we could call this additional 'holiday pay' or a longer 'weekend' and mandate it through law so that everyone benefits.
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...).
What about char arrays?
> 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.
> We ab^H^Huse [the Turing-completeness of printf()] to implement a the logic of tic-tac-toe entirely within this one printf call (and a call to scanf() to read user input).
So it should be "one printf() and one scanf()."
There is a call to scanf in the middle of the arg #define
Never in a million years would I have thought that printf() was Turing-Complete -- and yet, here's the proof that it is...
And then there's this related paper:
https://www.usenix.org/system/files/conference/usenixsecurit...
Page 175: "Printf is Turing-complete"
- esoteric modes of operation of a common function
- truly novel use of macros
- visibly beautiful
A more subtle touch is that the #defines spell out NOUGHTs AnD CRoSSES.
Suggests in my mind, somehow, thought I’d share: “CTRL-F oriented programming” :)
Aaargghhh MSVC 2019 doesn't like this :(
Dennis Ritchie HATES him. Program like a pro with this one weird trick! You won't believe what happens!
That's proper bait.