Separate my integers

21

3

Introduction

In the field of mathematics known as topology, there are things called separation axioms. Intuitively, you have a set X and a collection of subsets of X, which we can think of as properties. The system is well separated, if one can distinguish between all items of X based on their properties. The separation axioms formalize this idea. In this challenge, your task is to check three separation axioms, given X and the list of properties.

Input

Your inputs are an integer n ≥ 2, and a list of lists T of integers. The integers in T are drawn from X = [0, 1, ..., n-1]. The lists in T may be empty and unsorted, but they will not contain duplicates.

Output

Your output is one of four strings, determined by three separation axioms, each stronger than the last. There are other axioms, but we stick with these for simplicity.

  • Suppose that for all distinct x and y in X, there exists a list in T containing exactly one of them. Then X and T satisfy axiom T0.
  • Suppose that for all distinct x and y in X, there exist two lists in T, one of which contains x but not y, and the other contains y but not x. Then X and T satisfy axiom T1.
  • Suppose that the two lists above also contain no common elements. Then X and T satisfy axiom T2.

Your output is one of T2, T1, T0 or TS, depending on which of the above conditions holds (TS means none of them do). Note that T2 is stronger than T1, which is stronger than T0, and you should always output the strongest possible axiom.

Rules and scoring

You can write a full program or a function. The lowest byte count wins, and standard loopholes are disallowed.

Test cases

2 [] -> TS
2 [[],[1]] -> T0
2 [[0],[1]] -> T2
3 [[0],[0,1,2],[1,2]] -> TS
3 [[],[0],[0,1],[2]] -> T0
3 [[0],[0,1],[2,1],[0,1,2]] -> T0
3 [[0],[0,1],[2,1],[2,0]] -> T1
6 [[0,2,4],[0,3,5],[1,2],[3,4,5]] -> TS
6 [[0,2,4],[0,3,5],[1,2],[2,5],[3,4,5]] -> T0
6 [[0,2,4],[0,3,5],[1,2],[2,5],[3,1],[3,4,5]] -> T1
6 [[0,1],[0,2,3],[1,4],[2,4],[2,3,5],[1,3],[4,5]] -> T2

Zgarb

Posted 2016-01-07T02:26:18.710

Reputation: 39 083

Is the input n superfluous? In the rest of the challenge, I'm not seeing it used beyond defining what elements can be in T, so is it just a provided shortcut for T.Maximum()? – AdmBorkBork – 2016-01-07T14:20:47.540

@TimmyD, no. See the first test case. 0 [] should give T2. – Peter Taylor – 2016-01-07T14:56:22.880

@PeterTaylor Aaaahhhhhhhh. Thanks, that helps tremendously. – AdmBorkBork – 2016-01-07T15:01:27.260

Great explanation of what separability means! – Luis Mendo – 2016-01-07T21:15:49.583

@LuisMendo Weird terminology alert: These are separation axioms, and a topological spaces that satisfies T2 is sometimes called separated, but separability is something else entirely.

– Dennis – 2016-01-08T13:36:43.927

@Dennis Hm you're right, I mixed those up – Luis Mendo – 2016-01-08T21:39:48.807

Answers

9

Haskell, 317 209 174 168 bytes

The function f does the job.

(#)=elem
x?y=[1|a<-x,b<-y,not$any(#a)b]
f n l|t(++)="TS"|t zip="T0"|t(?)="T1"|1>0="T2"where
    t p=any null[p(x%y)(y%x)|x<-[0..n-1],y<-[0..x-1]]
    x%y=[z|z<-l,x#z,not$y#z]

tests :

main=do
    putStrLn $ f 2 []
    putStrLn $ f 2 [[],[1]]
    putStrLn $ f 2 [[0],[1]]
    putStrLn $ f 3 [[0],[0,1,2],[1,2]]
    putStrLn $ f 3 [[],[0],[0,1],[2]]
    putStrLn $ f 3 [[0],[0,1],[2,1],[0,1,2]]
    putStrLn $ f 3 [[0],[0,1],[2,1],[2,0]]
    putStrLn $ f 6 [[0,2,4],[0,3,5],[1,2],[3,4,5]]
    putStrLn $ f 6 [[0,2,4],[0,3,5],[1,2],[2,5],[3,4,5]]
    putStrLn $ f 6 [[0,2,4],[0,3,5],[1,2],[2,5],[3,1],[3,4,5]]
    putStrLn $ f 6 [[0,1],[0,2,3],[1,4],[2,4],[2,3,5],[1,3],[4,5]]

output:

TS
T0
T2
TS
T0
T0
T1
TS
T0
T1
T2

Damien

Posted 2016-01-07T02:26:18.710

Reputation: 2 407

Giving t a function as input is a clever trick! – Zgarb – 2016-01-07T19:44:51.090

In absence of competition, this bounty goes to your answer. Congratulations! – Zgarb – 2016-01-19T18:52:10.210

some free bytes - replace f by an operator name, and replace p(x%y)(x%y) by p(x%y)$x%y. and by the way, nice work! – proud haskeller – 2016-10-12T21:29:12.327