> source("http://www.cs.utoronto.ca/~radford/csc120/a1funs.r")
> source("http://www.cs.utoronto.ca/~radford/csc120/lab7-funs.r")

Try converting the small data set from Assignment 1 to matrix form.

> slink_data <- read_links(5,"http://www.cs.utoronto.ca/~radford/csc120/slink")
> 
> M <- matrix_from_list(slink_data)
> M
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    1    0    1    0
[2,]    1    0    1    1    0
[3,]    1    0    0    0    0
[4,]    1    1    1    0    0
[5,]    0    1    0    1    0

Convert to matrix form, transpose, and convert back to a list. The result shows which other web sites link to each web site.

> list_from_matrix (t (M))
[[1]]
[1] 2 3 4

[[2]]
[1] 1 4 5

[[3]]
[1] 2 4

[[4]]
[1] 1 2 5

[[5]]
numeric(0)

See where we can get in 2 or fewer links, 3 or fewer links, and 4 or fewer links.

> in_k_or_fewer_links(M,2)
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    1    1    0
[2,]    1    1    1    1    0
[3,]    1    1    0    1    0
[4,]    1    1    1    1    0
[5,]    1    1    1    1    0
> in_k_or_fewer_links(M,3)
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    1    1    0
[2,]    1    1    1    1    0
[3,]    1    1    1    1    0
[4,]    1    1    1    1    0
[5,]    1    1    1    1    0
> in_k_or_fewer_links(M,4)
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    1    1    1    0
[2,]    1    1    1    1    0
[3,]    1    1    1    1    0
[4,]    1    1    1    1    0
[5,]    1    1    1    1    0