Build a Twitter-quine

7

1

A short while, ago, @daniel_ernston sent the following challenge to @StackCodeGolf on Twitter:

@StackCodeGolf Your task is to build a program that uses the API of your choice to tweet its own source code. Shortest code wins, of course.

Joe Z.

Posted 2015-03-07T03:01:13.187

Reputation: 30 589

1What about reading the source code and other quine cheats? – Martin Ender – 2015-03-07T03:06:09.653

All permissible. I want to see how short you can get it, and I have a suspicion it may not be possible if I don't open those up. – Joe Z. – 2015-03-07T03:08:30.570

If you can come up with a solution that doesn't use that cheat, though, then by all means I'll give you an honourable mention (and maybe even a bounty). – Joe Z. – 2015-03-07T03:08:57.213

Hm, won't this depend quite heavily on the chosen user name and credentials? (Both whether it fits in the tweet and the actual score.) – Martin Ender – 2015-03-07T03:15:03.077

The challenge was written to be novel, not completely fair. However, I suppose you could create a throwaway account. – Joe Z. – 2015-03-07T03:18:59.133

11I don't have a twitter account and while I could create one, I have to give them my phone number to get an api key, maybe someone could post api keys from a throwaway account for everyone to use. This would also make the challenge fairer since they would be the same length. – Maltysen – 2015-03-08T19:25:09.153

Answers

9

JavaScript, 38 characters

window.open("http://tinyurl.com/erjk34");

Here is the tweet, in all its glory: https://twitter.com/kevinaworkman/status/575425948562014209

And here is my previous entry at 95 characters:

function q() {
window.open("https://twitter.com/intent/tweet?text="+encodeURIComponent(q+";{q();}"));
};{q();}

And if that's not cheating...

HTML, 22 characters

http://tinyurl.com/erjk35

Kevin Workman

Posted 2015-03-07T03:01:13.187

Reputation: 308

It this what was meant by tweeting or was it referring to the REST API https://dev.twitter.com/rest/public?

– Maltysen – 2015-03-10T20:51:05.133

@Maltysen It sends a tweet, so I'm counting it as fair game. It might be cheating, but hey, OP said that cheating was allowed! :p – Kevin Workman – 2015-03-10T20:56:10.213

1Okay then, +1 for loopholes. – Maltysen – 2015-03-10T21:05:54.513

I specifically said "the API of your choice", so this is okay. However, in order to count for this challenge, you will need to actually use your code to make a Twitter post, then link to it here. – Joe Z. – 2015-03-10T21:23:42.670

@JoeZ Done and done, and cheated even more. – Kevin Workman – 2015-03-10T22:43:00.203

I don't know much about Processing, but with vanilla JS you can remove the semicolon and window. because functions are automatically executed on the window object. You can also safely remove the https: protocol, leaving //tinyurl.... You'll have to regenerate the url, though. – NinjaBearMonkey – 2015-03-10T22:47:15.730

@hsl processing.js comes with the benefit of running without boilerplate, so I'll keep the semicolon instead. Good call with the // though. – Kevin Workman – 2015-03-10T23:03:14.183

1Well, uh, the TinyURL should post the tweet entirely by itself, without requiring you to press the "Tweet" button... – Joe Z. – 2015-03-10T23:48:51.787

...although I understand that may not be possible for security reasons. – Joe Z. – 2015-03-10T23:49:21.403

1@JoeZ. I went into this knowing that it was probably cheating- especially my last update, haha. I just figured it would be fun to try, especially since you didn't have any answers after 3 days! – Kevin Workman – 2015-03-11T00:00:31.307

This does not actually tweet its entire source code; the link shortener's expansion of the shortened link is also source code. – AJMansfield – 2015-03-11T00:06:44.943

For instance, this isn't considered a real quine: cat a, where a is just a text file containing the text cat a. (In that case, both the command and the file's contents are source code of the program, so the program needs to separately output the command and the contents of the file) – AJMansfield – 2015-03-11T00:12:16.757

@AJMansfield That doesn't make any sense. Are you saying you have to export the code for System.out.println() if you print your quine to the console? Also, see the above "cheating is okay" rule, where your example of reading from a file would be acceptable. But more to the point: this was supposed to be ridiculous, so just have fun with it. – Kevin Workman – 2015-03-11T00:13:54.657

@KevinWorkman No, because the implementation of System.out.println is part of the corpus of library code, not application code written for the purpose of the hypothetical quine. I am assuming, of course, that you did in fact create the link shortener redirection you are using - if that link was an existing link shortening that you found and are reusing, that would be a perfectly valid zeroth-order quine. – AJMansfield – 2015-03-11T00:18:23.117

@AJMansfield Eh, I think you're splitting hairs. The Windows machine I'm running on is also closed-source. Does that mean any quine that runs on it is invalid? I'm not saying my quine is valid, but I don't think I agree with your reasoning. Besides that, the OP specifically said that cheating was allowed and that you could do stuff like read from files, which is usually not "allowed" in quines. Either way, I'm sticking with my "this was supposed to be ridiculous" defense! :p – Kevin Workman – 2015-03-11T01:21:27.640

Also, you're saying that it would be fine if I "found" the shortened link, but not if I created it? That doesn't make much sense either. So if I had a partner who created the link for me, this would be okay? Again, I'm not saying this is the most honest or fair quine ever, but I don't agree with your logic here. – Kevin Workman – 2015-03-11T14:21:26.310

@KevinWorkman I have created a question on meta with regards to this: http://meta.codegolf.stackexchange.com/q/4877/7981

– AJMansfield – 2015-03-11T19:02:20.597

Let us continue this discussion in chat.

– AJMansfield – 2015-03-11T19:02:27.427

I am very sure you can take out window. Also, use a better/golfier URL shortener. – Mama Fun Roll – 2016-02-12T22:00:52.887