high-score-board

This commit is contained in:
Alexander Heldt
2025-11-08 15:30:12 +01:00
parent fad9b41d97
commit 84098e7db9
10 changed files with 369 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
import gleam/dict.{type Dict}
pub type ScoreBoard =
Dict(String, Int)
pub fn create_score_board() -> ScoreBoard {
dict.from_list([#("The Best Ever", 1_000_000)])
}
pub fn add_player(
score_board: ScoreBoard,
player: String,
score: Int,
) -> ScoreBoard {
dict.insert(score_board, player, score)
}
pub fn remove_player(score_board: ScoreBoard, player: String) -> ScoreBoard {
dict.drop(score_board, [player])
}
pub fn update_score(
score_board: ScoreBoard,
player: String,
points: Int,
) -> ScoreBoard {
case dict.get(score_board, player) {
Error(_) -> score_board
Ok(score) -> dict.insert(score_board, player, score + points)
}
}
pub fn apply_monday_bonus(score_board: ScoreBoard) -> ScoreBoard {
dict.map_values(score_board, fn(_, score) { score + 100 })
}