From c1e46f6c06e255bdaa9f0b66cf6757669ceba115 Mon Sep 17 00:00:00 2001 From: "exercism-solutions-syncer[bot]" <211797793+exercism-solutions-syncer[bot]@users.noreply.github.com> Date: Thu, 11 Dec 2025 15:50:45 +0000 Subject: [PATCH] [Sync Iteration] rust/high-scores/1 --- solutions/rust/high-scores/1/Cargo.toml | 9 +++++++ solutions/rust/high-scores/1/src/lib.rs | 31 +++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 solutions/rust/high-scores/1/Cargo.toml create mode 100644 solutions/rust/high-scores/1/src/lib.rs diff --git a/solutions/rust/high-scores/1/Cargo.toml b/solutions/rust/high-scores/1/Cargo.toml new file mode 100644 index 00000000..1e3a7727 --- /dev/null +++ b/solutions/rust/high-scores/1/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "high_scores" +version = "0.1.0" +edition = "2024" + +# Not all libraries from crates.io are available in Exercism's test runner. +# The full list of available libraries is here: +# https://github.com/exercism/rust-test-runner/blob/main/local-registry/Cargo.toml +[dependencies] diff --git a/solutions/rust/high-scores/1/src/lib.rs b/solutions/rust/high-scores/1/src/lib.rs new file mode 100644 index 00000000..dd7ce3ae --- /dev/null +++ b/solutions/rust/high-scores/1/src/lib.rs @@ -0,0 +1,31 @@ +#[derive(Debug)] +pub struct HighScores { + scores_vec: Vec, +} + +impl HighScores { + pub fn new(scores: &[u32]) -> Self { + HighScores { + scores_vec: scores.to_vec(), + } + } + + pub fn scores(&self) -> &[u32] { + &self.scores_vec + } + + pub fn latest(&self) -> Option { + self.scores_vec.last().copied() + } + + pub fn personal_best(&self) -> Option { + self.scores_vec.iter().max().copied() + } + + pub fn personal_top_three(&self) -> Vec { + let mut sorted_scores = self.scores_vec.to_vec(); + sorted_scores.sort(); + sorted_scores.reverse(); + sorted_scores.iter().take(3).copied().collect() + } +} \ No newline at end of file