News for hackers. Stuff that matters.
Re:Show HN: XKCD-inspired StackSort by recuter on Monday March 18, 2013 @01:21PM (#5395616)
If you give it about 30 seconds it works eventually, this is beautiful. I had a good laugh.

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!

Re:Show HN: XKCD-inspired StackSort by dmitshur on Monday March 18, 2013 @02:21PM (#5396113)
I tried a basic version of that 1.5 weeks ago. At first it was generating random characters, then I tried some Markov chains trained on valid code.

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).

Re:Show HN: XKCD-inspired StackSort by Retric on Monday March 18, 2013 @04:13PM (#5396823)
If you actually want to go down this path then you want a language with as little redundancy as possible. Comments may be useful to humans but they needlessly complicate the search space. Abstractly you want to think about the how your language is parsed so you don't for example try different variable names.

Though if you spend enough time your probably going to be reimplementing some type of http://en.wikipedia.org/wiki/Genetic_programming

Re:Show HN: XKCD-inspired StackSort by omra on Monday March 18, 2013 @05:23PM (#5397218)
[Slash/A](https://github.com/arturadib/slash-a) is specially designed for genetic programming / random generation. No matter how you piece together the instructions, it is still a valid program.
Re:Show HN: XKCD-inspired StackSort by Falling3 on Monday March 18, 2013 @04:39PM (#5396976)
Like maybe Brainfuck?
Re:Show HN: XKCD-inspired StackSort by shurcooL on Monday March 18, 2013 @04:46PM (#5397026)
Yep, I was considering directly generating the AST.
Re:Show HN: XKCD-inspired StackSort by nathell on Monday March 18, 2013 @02:26PM (#5396153)
Try this in Forth, or Factor. And be sure to read up on genetic programming.

http://en.wikipedia.org/wiki/Genetic_programming

Re:Show HN: XKCD-inspired StackSort by shurcooL on Monday March 18, 2013 @02:30PM (#5396175)
I will read more about GP for future attempts, thanks.
Re:Show HN: XKCD-inspired StackSort by recuter on Monday March 18, 2013 @02:43PM (#5396277)
This is an exciting exchange for me because all joking aside I had this idea in the past and believe it should be a more active area of research.

Why Forth?

I doubt it is possible to solve "serious" problems with this approach but there is a whole class of work that is solved by mediocre programmers with copy pasting. We strive to automate other jobs, why not these? :)

We should come up with some sort of Turing like test for this. Like some small simple Wordpress job.

Re:Show HN: XKCD-inspired StackSort by vidarh on Tuesday March 19, 2013 @06:11AM (#5399924)
Genetic programming is an active area of research, and there has been a number of successes. See John R. Koza's work: http://www.genetic-programming.com/johnkoza.html for starters.

It's not really, so far at least, suitable for replacing work done by mediocre programmers, because the setup cost is so high: The hard work is defining the fitness function and symbol set and other factors, and to pay off this requires problems where it is easier to recognise a good result than writing the algorithm to achieve it.

E.g. a sort function does not fall in that space: Once you've specified how you want your data sorted, you've usually done most of the work.

But once you've specified the fitness function sufficiently well, and figured out the inputs etc., there are a lot of other search algorithms that often will perform better.

I'm very fascinated by GP too (though I've never had time to truly delve into it), but without combining it with mechanisms to take a large chunk of the specification work out of the equation, it remains confined to fairly specific types of problems.

Re:Show HN: XKCD-inspired StackSort by RodgerTheGreat on Monday March 18, 2013 @05:09PM (#5397145)
Forth, Factor, APL or any other concatenative language provides the benefit of a "point free" style in which there are no explicitly named variables- that's one way to reduce the possibility space of programs. In the case of Factor (or Forth with an appropriate DSL) you could further use type information to ensure that your program generator only used words in sequence whose stack effects match up properly- ie a 'valid' program. Concatenative languages also tend to have an extremely simple grammar- Forth is just a sequence of tokens and numbers.
Re:Show HN: XKCD-inspired StackSort by fizx on Monday March 18, 2013 @05:18PM (#5397185)
Perhaps worth noting: java bytecode is a concatenative language. There are probably more commercially interesting java corpora than forth corpora.

If you want to get paid to play around with this thought, my contact info is in my HN profile.

Re:Show HN: XKCD-inspired StackSort by RodgerTheGreat on Monday March 18, 2013 @06:04PM (#5397475)
Java bytecode is stack-based, but it isn't really concatenative. The term "concatenative" refers to how code fragments can be composed via concatenation. This means that simple textual substitution is sufficient for inlining code or breaking code into functions. For example, consider a Forth word which determines whether a number is divisible by three or five:

  : fizzbuzzable  dup 3 mod 0= swap 5 mod 0= or ;
There's a repeated pattern here, so we can textually excise it and make it into a named word without changing any of the structure of the surrounding program:

  : /?            mod 0=                ;
  : fizzbuzzable  dup 3 /? swap 5 /? or ;
Or we could break it down a different way by excising different fragments:

  : /3?           3 mod 0=            ;
  : /5?           5 mod 0=            ;
  : fizzbuzzable  dup /3? swap /5? or ;
(Obviously not the best real-world example, but hopefully it illustrates the idea.)

Java bytecode, on the other hand, uses local variable references and activation records. This means that inlining or breaking out a procedure has pretty much the same problems as inlining or breaking out a procedure manually in C- variable names may clash, new arguments have to be threaded around, parts of expressions may need to be stored in temporary variables, etc. the JVM additionally enforces many constraints on "well-formed" bytecode at class load time[1] which could make it hard to generate valid programs by chance. Overall, Trying to "harvest" java bytecode from the wild could be useful, but I think that would be much harder than it sounds at first.

[1] http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.htm... (and below)

Re:Show HN: XKCD-inspired StackSort by randomsearch on Tuesday March 19, 2013 @08:47AM (#5400514)
"...believe it should be a more active area of research."

8000 papers so far:

http://www.cs.bham.ac.uk/~wbl/biblio/

Re:Show HN: XKCD-inspired StackSort by morphics on Monday March 18, 2013 @03:51PM (#5396698)
If you want to learn about GP, the Genetic Programming Field Guide - http://www.gp-field-guide.org.uk/ - is an awesome book, it taught me a lot. In fact, I liked it so much, I bought a hard copy. Highly recommended!
Re:Show HN: XKCD-inspired StackSort by randomsearch on Tuesday March 19, 2013 @08:42AM (#5400491)
I'd also recommend Wolfgang Banzhaf's book on GP:

http://www.amazon.co.uk/Genetic-Programming-Introduction-Art...

Re:Show HN: XKCD-inspired StackSort by veaviticus on Monday March 18, 2013 @03:03PM (#5396399)
Check out this article. Same concept, using genetic programming

http://www.primaryobjects.com/CMS/Article149.aspx

Re:Show HN: XKCD-inspired StackSort by shurcooL on Monday March 18, 2013 @03:16PM (#5396484)
That's pretty sweet, thanks.

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.

Re:Show HN: XKCD-inspired StackSort by errnoh on Monday March 18, 2013 @04:18PM (#5396851)
Hah, fun idea.

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/sec
Re:Show HN: XKCD-inspired StackSort by shurcooL on Monday March 18, 2013 @04:52PM (#5397060)
Cool, let me know the best you get (and submit a PR with your parallel patch if you want).

You 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.

Re:Show HN: XKCD-inspired StackSort by bo1024 on Monday March 18, 2013 @05:09PM (#5397146)
The key last step is to have it automatically post questions to StackOverflow to fill in the last code snippets it can't complete.
Re:Show HN: XKCD-inspired StackSort by conrad24 on Monday March 18, 2013 @07:12PM (#5397797)
I did this in my machine learning class. I started by simply coding up requirements for numerical functions (in the form of test cases), then set up a PHP script that would Google each function based on the keywords in my comments, and try to run any code on the resulting links (in a sandbox) against the requirements, seeing if it worked heuristically. Usually one of the top 5-10 pages of results results would have code that worked, though of course this is because I commented with the right key words to begin with.

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?

Re:Show HN: XKCD-inspired StackSort by bo1024 on Monday March 18, 2013 @07:49PM (#5397934)
Don't feel bad, you just fell into one of the common traps for first-timers in strong AI/ML. I know some lawyers in Silicon Valley with experience in this sort of thing, and they say that usually by now the code has rewritten itself so many times that the original creator can't even claim partial ownership; the best thing to do is generally to cut contact, change your name and move on. Look on the bright side -- your algorithm is probably now leading a happy and productive life trading for Goldman Sachs.
Re:Show HN: XKCD-inspired StackSort by recuter on Monday March 18, 2013 @07:54PM (#5397962)
I was still hoping this was real 5 lines in.
Re:Show HN: XKCD-inspired StackSort by vidarh on Tuesday March 19, 2013 @05:48AM (#5399839)
Now I want to try it.

I mean, I used to regularly got initial e-mail screening answers from candidates for various positions that were cut and pasted from Google (very obvious because they were so far out of what we expected that we cut and pasted a line here and there and got back "their" answer word for word - often wrong). And these were people already in developer jobs, which makes me wonder if they'd used that method in their jobs or to get them...

Re:Show HN: XKCD-inspired StackSort by pfarrell on Tuesday March 19, 2013 @12:41AM (#5398989)
Conrad24: this post made my day. I have dreamed of a script that would scour eBay and amazon finding products available via "buy now" that we're being resold on amazon for some configurable profit. Or vice versa. I figure with some initial investment and monitored training, it could get good enough to just cut me a check every month. Since high frequency trading has destabilized the stock market, this could be a better high risk investment.
Re:Show HN: XKCD-inspired StackSort by vidarh on Tuesday March 19, 2013 @05:44AM (#5399823)
My ex has a standing rule whenever buying stuff of e-bay to always check misspellings, and there's regularly items going very cheaply with misspelled items. I'm sure there's an opportunity there, but hard to gauge how big. Especially with relatively small ticket items that people just want to get rid off.

E.g. toys - there's a thriving market in Lego minifigures. In fact, sometimes the minifigures can individually fetch more than the set, because for many of the ranges, all the sets will contain different subsets of recognizable characters, so there's often a market consisting of people that have e.g. 3 of the 4 ninja turtles and want the last one without paying for a full set. So the prices are already ridiculously high for some items.

But many of the people in that market are totally unsophisticated. For example parents selling of their kids collections once they've "grown out of it", and when they misspell something, items can go for 1/4 of their market value or even less...

If you're willing to hold on to them and monitor prices for a while, you can do even better, as many of the ranges appreciate substantially in value (big collectors market...).

Re:Show HN: XKCD-inspired StackSort by rmc on Tuesday March 19, 2013 @06:31AM (#5399990)
I'd have thought that eBay would have improved their search algorithm to take into account misspellings like that by now...
Re:Show HN: XKCD-inspired StackSort by grimman on Tuesday March 19, 2013 @07:48AM (#5400273)
They have no reason to. The initial (mis-spelled) sale will net them their expected revenue, and by allowing people to flip goods at a profit they are now also sharing a piece of the (regurgitated?) cake. Same item, double the income... and at what price? Developer hours? Not at all!
Re:Show HN: XKCD-inspired StackSort by PanMan on Monday March 18, 2013 @07:49PM (#5397937)
I now really want to know what part of this story is true.
Re:Show HN: XKCD-inspired StackSort by waterlesscloud on Tuesday March 19, 2013 @06:37AM (#5400003)
This is perhaps my all-time favorite HN comment.
Re:Show HN: XKCD-inspired StackSort by tianshuo on Tuesday March 19, 2013 @02:12AM (#5399254)
Next step, deal weapons of mass destruction using bitcoins. Final step, skynet...
Re:Show HN: XKCD-inspired StackSort by rmc on Tuesday March 19, 2013 @06:31AM (#5399989)
Have you read Charlie Stross' Accelerando? It's basically about the technological singularity, and starts off something like this. It's available for free on his website.
Re:Show HN: XKCD-inspired StackSort by hawkw on Tuesday March 19, 2013 @09:38AM (#5400770)
You sir are a god amongst men.
Re:Show HN: XKCD-inspired StackSort by vanderZwan on Monday March 18, 2013 @06:16PM (#5397532)
"And that, Neo, is how computers became self-aware and learned to exploit human brain-cycles, eventually resulting in the Matrix."
Re:Show HN: XKCD-inspired StackSort by worldsayshi on Tuesday March 19, 2013 @05:31AM (#5399792)
This was an early idea for the Matrix wasn't it. Machines using human brains for processing power.
Re:Show HN: XKCD-inspired StackSort by pilsetnieks on Tuesday March 19, 2013 @06:22PM (#5404010)
From a random sample of first-page StackOverflow questions I could swear that someone has already done just that.
Re:Show HN: XKCD-inspired StackSort by gkoberger on Monday March 18, 2013 @01:26PM (#5395671)
Ah, applying the Infinite monkey theorem to programming :)

http://en.wikipedia.org/wiki/Infinite_monkey_theorem

Re:Show HN: XKCD-inspired StackSort by fnordfnordfnord on Monday March 18, 2013 @03:13PM (#5396463)
Yeah, but there are a few well trained monkeys hanging out [mining for karma points] at StackOverflow. The really adventurous would direct it at 4chan.
Re:Show HN: XKCD-inspired StackSort by redthrowaway on Monday March 18, 2013 @05:09PM (#5397147)
Direct at at /prog/ and you may eventually run across SleepSort, which would at least do something mildly useful (in >30 languages, no less!)
Re:Show HN: XKCD-inspired StackSort by vanderZwan on Tuesday March 19, 2013 @06:01AM (#5399890)
Since 4chan threads are thrown away, it lacks the "hereditary" trait of the variation/selection/heredity trio. Unless you include one of the sites that archives popular threads I suppose.
Re:Show HN: XKCD-inspired StackSort by fdb on Monday March 18, 2013 @03:27PM (#5396556)
I've created a weekend hack that allows you to specify a minimal grammar and then generates text (which can be code) using it.

It's called Choice Words (https://github.com/fdb/choicewords) It can generate poems but also generative designs (see the README).

Re:Show HN: XKCD-inspired StackSort by Steph0r on Monday March 18, 2013 @04:37PM (#5396959)
That generated drawing in the README.md looks like something i'd hang in my kitchen. You should try selling these ;)
Re:Show HN: XKCD-inspired StackSort by randomsearch on Tuesday March 19, 2013 @08:49AM (#5400522)
You've just re-invented Grammatical Evolution.

http://en.wikipedia.org/wiki/Grammatical_evolution

Re:Show HN: XKCD-inspired StackSort by Tyrannosaurs on Tuesday March 19, 2013 @04:16AM (#5399548)
> Throw enough resources at it maybe it will be faster and cheaper than your avg. developer.

> It will be an unmaintainable mess.

So cheaper than your average developer with about the same code quality?

Re:Show HN: XKCD-inspired StackSort by TheAnimus on Monday March 18, 2013 @01:26PM (#5395664)
Worst case scenario, Shakespeare.
Re:Show HN: XKCD-inspired StackSort by rmc on Tuesday March 19, 2013 @06:24AM (#5399963)
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.

This exists. It's called Genetic Algorithms. You basically try to "evolve" your algorithm.

Re:Show HN: XKCD-inspired StackSort by randomsearch on Tuesday March 19, 2013 @08:48AM (#5400520)
Genetic Programming is closer.
Re:Show HN: XKCD-inspired StackSort by veaviticus on Monday March 18, 2013 @03:01PM (#5396379)
Re:Show HN: XKCD-inspired StackSort by Terretta on Monday March 18, 2013 @05:44PM (#5397358)
> if you used Brainfuck or Perl

TMTOWTDI, dammit.

Re:Show HN: XKCD-inspired StackSort by yen223 on Monday March 18, 2013 @07:49PM (#5397936)
"There's more than one way to do it", if anyone else was as puzzled as I was.
Re:Show HN: XKCD-inspired StackSort by prawks on Monday March 18, 2013 @02:08PM (#5396008)
Could be a new declarative language.
Re:Show HN: XKCD-inspired StackSort by Vivtek on Monday March 18, 2013 @02:38PM (#5396230)
Aaand I just heard the death knell of H. sapiens domination of the planet.