Write a program that converts between representations of binary relations: from a set-of-ordered-pairs representation to a matrix representation.
In this exercise, by convention, we deal with relations over the finite set of natural numbers from 0 to n-1.
Input will contain several relations R represented
as a list of pairs.
Each representation begins with a line containing a number n
followed zero or more lines
each containing a pair of numbers x and y
followed by a line containing a dash -
.
The number n represents the size of the domain and co-domain.
Each pair x and y indicates that x is related to y (xRy).
Input is given so that 0 ≤ x, y < n < 100.
For each relation given in the input, output should contain a 0-1 matrix representation of the given relation followed by a blank line.
3
0 1
1 2
0 2
-
4
1 1
2 2
-
0 1 1
0 0 1
0 0 0
0 0 0 0
0 1 0 0
0 0 1 0
0 0 0 0
try first: set-member
try also: rel-mtol
try next: rel-member
Copyright © 2020-2021 Rudy Matela
This text is available under the CC BY-SA 4.0 license.
Originally available on cscx.org/rel-ltom