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.