14
Here are all the 2x2 binary matrices
#0 #1 #2 #3 #4 #5 #6 #7 #8 #9 #10 #11 #12 #13 #14 #15
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
00 00 00 00 01 01 01 01 10 10 10 10 11 11 11 11
00 01 10 11 00 01 10 11 00 01 10 11 00 01 10 11
Two binary square matrices are equivalent under the relation ~
if one can be mapped onto the other by any number of reflections in the horizontal or vertical axes.
#1 ~ #2
under reflection in the vertical axis so we only need to keep one of these (it doesn't matter which). Likewise #3 ~ #12
, #6 ~ #9
and so on.
THE GOAL is to produce a program which takes a single input N
and prints as many N x N
binary matrices as exist such that all matrices in the output are distinct under the above relation.
In hand-wavey pseudocode, an admissible solution would be
define M[i] = N by N matrix with bit pattern equal to i
for i = 0 to (2^(N^2)) - 1
valid = true
for j = i+1 to (2^(N^2)) - 1
if (equivalent(M[i], M[j]))
valid = false
break
if (valid)
print (M[i])
For the input N=2
one valid output would be
00 00 00 01 10 01 11
00 01 11 01 01 11 11
But by selecting different matrices from the same equivalence class another valid output would be
00 10 11 11 11 10 01
00 00 00 10 11 10 10
The order of matrices doesn't matter, the particular choice from equivalent matrices doesn't matter, and whitespace doesn't matter, output the matrices however you like as long as it's human-readable.
The output must be exhaustive.
Shortest code wins.
EDIT: this is my first golf post and I've changed my mind on the winning criteria.
Shortest code in a language not specifically designed for conciseness/golfing wins.
I hope it's not bad etiquette to change this criterion post-hoc, but I think doing it in a "normal" language is a much more interesting proposition.
5Welcome to PPCG! This is a nice first challenge, but I'd recommend letting people output the result in a flexible format (e.g. each matrix as a list of lists). That way people can focus on the very interesting core of the challenge (finding the unique matrices up to symmetries) instead of also having to worry about formatting the output (which could easily take just as many bytes and make the golfing of the main challenge less important). – Martin Ender – 2016-10-04T20:38:49.730
Thanks for the feedback, both of you, I have edited the question accordingly. – spraff – 2016-10-04T21:07:29.383
I'd also recommend posting future challenge ideas in the sandbox where you can get feedback for it before the challenge goes live and people might start working on it.
– Martin Ender – 2016-10-04T21:27:55.657Out of interest, why exclude rotations? – Neil – 2016-10-05T09:42:54.587
2I was tempted to include rotations as an equivalence. I was also tempted to include inverting each bit as an equivalence. I was also tempted to include permutations of rows/columns as an equivalence. In the end, I made an arbitrary decision to keep the requirements fairly simple. Feel free to post a variation. – spraff – 2016-10-05T13:38:28.723
1We've discussed this in the past and ruled against excluding or penalizing certain languages in code golf competitions, meaning that challenge that do so should be considered off topic. Furthermore, the accepted answer is the answer that wins the challenge, which means shortest code for code golf questions. Summarizing: If you don't want to accept any answer at all, then don't. However, if you accept an answer, it has to be the shortest one. – Dennis – 2016-10-06T18:47:32.310
1
Finally, the J language is not a golfing language, but a high-level, general-purpose, high-performance programming language that has existed for 25 years. Even with your current rules, you've still accepted the wrong answer.
– Dennis – 2016-10-06T18:50:22.430It's your choice. Meanwhile I change my vote from +1 to -1 – edc65 – 2016-10-06T19:01:08.160
Fair enough on J, @Dennis I accepted that one. My 2 cents on this issue is: if a language advertises itself as a golfing language then that's a bit cheeky. To respond to the analogy in the accepted answer, it's like going to a rifle range and asking people to actually hold the gun rather than use a tripod-mounted-stepper-motor to aim.
– spraff – 2016-10-06T19:36:48.897