# Rosalind: TREE — Completing a Tree # https://rosalind.info/problems/tree/ # # Given: A positive integer n and an adjacency list of a graph on n nodes that # forms a forest. # Return: The minimum number of edges needed to produce a tree. let n = 10 let edge_list = [[1,2],[2,8],[4,10],[5,9],[6,10],[7,9]] # A tree on n nodes has exactly n-1 edges, and a forest with e edges has # n-e components — so joining them needs (n-1)-e more. let result = (n - 1) - len(edge_list) println("Result: " + str(result)) println("Expected: 3") fn test_tree_edges_to_add() { assert result == 3, "TREE: got " + str(result) }