3
Introduction
You may remember sudoku, where there can only be one of each number in each row, column and block of nine. The general idea is that if the array contains but one element, you can submit that as a deterministic solution. If there are already filtered arrays (by rows, columns and 3×3 blocks) the remainder can still be deterministic. Where
- a=[1,2];
- b=[1,3];
- c=[2,3];
- d=[1,2,3,4]
d should be reduced to [4] as it apparently cannot be anything else.
Challenge
Provide a sniplet that compares n arrays. For every X, if only X numbers appear at least once in a set of X arrays, then all those X numbers should be removed from each array not in the set. The elements are integer numbers ranging [1, n].
Winning criterion
Lowest character count.
"I'm too young to die" version
9 arrays at most, 9 elements at most.
Test Cases
[1,2]; [2,3]; [1,3]; [1,2,3,4]
[1,2,3]; [2,3,4]; [1,5,6]; [2,3]; [1,4]; [1,2,3,4,6]Test outputs
[1,2]; [2,3]; [1,3]; [4]
[1,2,3]; [2,3,4]; [5]; [2,3]; [1,4]; [6]
"the numerosity of elements of 1 to n arrays' union equals to the numerosity of arrays". Does this mean that there are
n
arrays in the input, and their union is exactly[1,2,...,n]
? Also, I don't really understand the challenge. What should the output be in your example? – Zgarb – 2015-02-06T11:10:06.280The output should be in the above case [1,2]; [1,3]; [2,3] and [4]. The numerosity of arrays is not necessarily the same as the numerosity of their union's elements, the array reduction is a more general operation. – user3819867 – 2015-02-06T11:18:49.647
What is this about ""I'm too young to die" version"? The formatting suggests that it's part of the winning criterion, but that makes no sense. I think you probably want cascading deductions, but the question doesn't mention them: it should (either to say that they're required or that they aren't). – Peter Taylor – 2015-02-06T11:24:52.840
It would also be helpful to state whether the elements of the arrays are always integers, and if so whether they always fall within a given range. That could allow some answers to save bytes. – Peter Taylor – 2015-02-06T11:26:28.250
The "I'm too young to die" version is for lazy bums who don't want to test what they've written. Larger set combinatorics are a nasty thing. Anyways, the tests (sorry for the edit) fall within the bottleneck of 9 elements, 9 sets. – user3819867 – 2015-02-06T11:29:50.833
If the intention is to have two winners then I'm afraid that's not possible. This site's software only allows one accepted answer. – Peter Taylor – 2015-02-06T12:28:16.117
I can't make sense of what the task is here. Could someone who does please explain? – xnor – 2015-02-07T00:21:41.343
@feersum The
1
inb
should be removed according to your interpretation. – jimmy23013 – 2015-02-07T11:22:45.340