Last active
April 6, 2024 16:21
-
-
Save lrlucena/8dbcc6d95c6ab6f66557ed689b542ffb to your computer and use it in GitHub Desktop.
Matemática Discreta - Composição de Relações
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Amizade = [('A', 'B'), ('B', 'A'), ('B', 'C'), ('C', 'B'), ('A', 'D'), ('D', 'A')] | |
AmigosDeAmigos = | |
para a em Amizade, b em Amizade | |
se a.segundo == b.primeiro e # (x,y) e (y,z) => (x,z) | |
a.primeiro <> b.segundo e # x <> z | |
não Amizade.contém((a.primeiro, b.segundo)) | |
gere (a.primeiro, b.segundo) | |
fim | |
escreva AmigosDeAmigos |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Amizade = [('A', 'B'), ('B', 'A'), ('B', 'C'), ('C', 'B'), ('A', 'D'), ('D', 'A')] | |
AmigosDeAmigos = [] | |
for a in Amizade: | |
for b in Amizade: | |
if a[1] == b[0] and a[0] != b[1] and (a[0], b[1]) not in Amizade: | |
AmigosDeAmigos.append((a[0], b[1])) | |
print(AmigosDeAmigos) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val amizade = Set(('A', 'B'), ('B', 'A'), ('B', 'C'), ('C', 'B'), ('A', 'D'), ('D', 'A')) | |
val amigosDeAmigos = | |
for (a, b) <- amizade | |
(c, d) <- amizade | |
if b == c && a != d && !amizade.contains((a, d)) | |
yield (a, d) | |
def imprimir(r: Set[?]) = println(r.mkString("{", ", ", "}")) | |
@main | |
def main(): | |
imprimir(amigosDeAmigos) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Amizade = {('A', 'B'), ('B', 'A'), ('B', 'C'), ('C', 'B'), ('A', 'D'), ('D', 'A')} | |
AmigosDeAmigos = {(a, d) for (a, b) in Amizade for (c, d) in Amizade if b == c and a != d and (a, d) not in Amizade} | |
print(AmigosDeAmigos) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment