-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2018-04-06.jl
46 lines (41 loc) · 1.66 KB
/
2018-04-06.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using JLD, BenchmarkTools
function parse_games()
cd("C:\\Users\\gabeh\\OneDrive\\Documents\\Programming\\Riddlers")
file = open("NCAA.txt")
lines = readlines(file)
close(file)
n = length(lines)
teams = Array{String}(n, 2)
for i = 1:n
line = lines[i]
team1 = strip(line[13:36])
team2 = strip(line[42:65])
teams[i, 1:2] = [team1, team2]
end
return teams
end
function get_teams_list(teams::Array{String, 2})
list = union(teams[:, 1], teams[:, 2])
list = union(list, list)
return list
end
#THIS FUNCTION ACTUALLY FINDS THE TRANSITIVE CHAMPIONS
function find_champions(team::String, teams::Array{String, 2}, champions::Array{String, 1})
games_lost = findin(teams[:, 2], [team]) #finds the indices for the games the team lost
new_champs = teams[:, 1][games_lost] #gets the team names of the winners of those games
actually_new = setdiff(new_champs, champions) #ensures that you haven't already accounted for any of the winners
champions = vcat(champions, actually_new) #merges the previous champions with the new ones
for champ in actually_new
new_champs = find_champions(champ, teams, champions) #recursively finds the teams that beach each new transitive champ
champions = union(champions, new_champs)
end
return champions
end
println("Parsing")
teams = parse_games()
teams_list = get_teams_list(teams)
champions = ["Villanova"]
champions = find_champions("Villanova", teams, champions)
println("Number of Teams that are NOT Champions or Transitive Champions:")
println(length(teams_list) - length(champions))
display(@benchmark find_champions("Villanova", teams, champions))