In this exercise, you're implementing a way to keep track of the high scores for the most popular game in your local arcade hall.
To add a player to the high score board, define two add_player! methods that take the following arguments:
julia> scores = Dict{String, Int}()
Dict{String, Int64}()
julia> add_player!(scores, "Liselot", 486373)
Dict{String, Int64} with 1 entry:
"Liselot" => 486373
julia> add_player!(scores, "Éimhín")
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 0To remove a player from the high score board, define remove_player!, which takes 2 arguments:
julia> scores = Dict(
"Liselot" => 486373,
"Éimhín" => 0,
)
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 0
julia> remove_player!(scores, "Liselot")
Dict{String, Int64} with 1 entry:
"Éimhín" => 0To update a players score by replacing the previous score, define update_score!, which takes 3 arguments:
julia> scores = Dict(
"Liselot" => 486373,
"Éimhín" => 0,
)
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 0
julia> update_score!(scores, "Éimhín", 89479) # TODO: Should this return the dict?
89479
julia> scores
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 89479To reset a player's score, define reset_score!, which takes 2 arguments:
julia> scores = Dict(
"Liselot" => 486373,
"Éimhín" => 0,
)
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 0
julia> reset_score!(scores, "Liselot") # TODO: Should this return the dict?
0
julia> scores
Dict{String, Int64} with 2 entries:
"Liselot" => 0
"Éimhín" => 0To get a list of players, define players, which takes 1 argument:
julia> scores = Dict(
"Liselot" => 486373,
"Éimhín" => 0,
)
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 0
julia> players(scores)
2-element Vector{String}:
"Liselot"
"Éimhín"In this exercise, you're implementing a way to keep track of the high scores for the most popular game in your local arcade hall.
To add a player to the high score board, define two add_player! methods that take the following arguments:
julia> scores = Dict{String, Int}()
Dict{String, Int64}()
julia> add_player!(scores, "Liselot", 486373)
Dict{String, Int64} with 1 entry:
"Liselot" => 486373
julia> add_player!(scores, "Éimhín")
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 0To remove a player from the high score board, define remove_player!, which takes 2 arguments:
julia> scores = Dict(
"Liselot" => 486373,
"Éimhín" => 0,
)
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 0
julia> remove_player!(scores, "Liselot")
Dict{String, Int64} with 1 entry:
"Éimhín" => 0To update a players score by replacing the previous score, define update_score!, which takes 3 arguments:
julia> scores = Dict(
"Liselot" => 486373,
"Éimhín" => 0,
)
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 0
julia> update_score!(scores, "Éimhín", 89479) # TODO: Should this return the dict?
89479
julia> scores
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 89479To reset a player's score, define reset_score!, which takes 2 arguments:
julia> scores = Dict(
"Liselot" => 486373,
"Éimhín" => 0,
)
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 0
julia> reset_score!(scores, "Liselot") # TODO: Should this return the dict?
0
julia> scores
Dict{String, Int64} with 2 entries:
"Liselot" => 0
"Éimhín" => 0To get a list of players, define players, which takes 1 argument:
julia> scores = Dict(
"Liselot" => 486373,
"Éimhín" => 0,
)
Dict{String, Int64} with 2 entries:
"Liselot" => 486373
"Éimhín" => 0
julia> players(scores)
2-element Vector{String}:
"Liselot"
"Éimhín"