Wireless Keyboard Inteference Initech are setting up an office of 36 employees in a soul-crushingly efficient square of cubicles, 6 desks long and 6 desks deep.  Management has bought wireless keyboards in bulk from a cheap, international wholesaler.  IT are quickly discovering that the wireless keyboards only operate on 3 different radio frequencies, and each individual keyboard is hardwired to a particular frequency.  When two keyboards on the same frequency are too close to each other, they interfere with each other.  The only identifying mark on the keyboards is a unique serial number which gives no clues as to the keyboard's radio frequency.  Thankfully there are an equal number of keyboards operating on each frequency.

A keyboard can be defined by the following class.

sealed class WirelessKeyboard
{
    private int frequency;
    private int serialNum;

    public WirelessKeyboard(int frequency, int serialNum)
    {
        this.frequency = frequency;
        this.serialNum = serialNum;
    }

    public bool InteferesWith(WirelessKeyboard other)
    {
        return this.frequency == other.frequency;
    }

    public int getSerialNum()
    {
        return serialNum;
    }
}


Your function must accept an array of 36 WirelessKeyboard objects.  Each is predefined with a unique serial number and one of the three frequencies (12 keyboards of each frequency).  The array is in random order.  The only way to determine a keyboard's frequency is to test if it interferes with another keyboard.

Your function must:


Not modify or extend the WirelessKeyboard class beyond translating it into your programming language of choice.
Accept an input array of WirelessKeyboard objects.
Not create or alter any WirelessKeyboard objects.  Only those in the input may be used.
Not use any means (eg. reflection) to read a keyboard's frequency.
Output a 6x6 array (or equivalent) populated with WirelessKeyboard objects, which:

Contains all 36 unique keyboards.
InteferesWith(other) must return false for all horizontally and vertically adjacent keyboards.



For the sake of code golf, the WirelessKeyboard class may be aliased as K and code may be written as a function.  For example, in C/Java, ungolfed and golfed:

WirelessKeyboard[,] FindMap(WirelessKeyboard[] collection) { ... }

K[,]F(K[]c){ ... }


The shortest code in a week gets the points.  Please post your implementation of the WirelessKeyboard class if it differs significantly from the sample above, but do not count it towards your score.  The function and any dependant declarations (eg. library imports) count towards your score.
Julia, 97 chars

s(k)=while any([k[j]&gt;k[j-1]||j&gt;6&amp;&amp;k[j]&gt;k[j-6] for j=2:36]);i,j=rand(1:36,2);k[[i,j]]=k[[j,i]];end


Checks if the array is in an acceptable final state state, if not, randomly flips two entries. It's super slow, which I find highly amusing. Does an in place alteration on the input array k. InterferesWith is implemented as &gt;.

As I said, it's really slow.  I tested it with more frequencies and smaller boards with 3 frequencies, but it hasn't returned in over 30 mins on the actual problem. I suspect that it won't return overnight, but I'll update if it does. Update: Yes it did finish in less than 12 hours, and yielded an answer that I added to the gist.

Gist with commented code, and includes 3x3 test case that finishes fast: https://gist.github.com/ggggggggg/8679916