Skip to content

Instantly share code, notes, and snippets.

@mrbus
mrbus / rs
Created March 3, 2025 07:15
Rust Developer Intern - Task 2
// Add this module to your main code
#[cfg(test)]
mod tests {
use super::*;
fn make_stamps() -> Vec<Stamp> {
vec![INITIAL_STAMP,
Stamp {offset: 1, score: Score {home: 0, away: 0}},
Stamp {offset: 2, score: Score {home: 1, away: 0}},
Stamp {offset: 4, score: Score {home: 1, away: 0}},
@mrbus
mrbus / gist:05c0a67a518fceb05fc14877282b21d6
Created March 2, 2025 20:34
Rust Developer Intern - Task 1
pub fn get_score(game_stamps: &[Stamp], offset: i32) -> (i32, i32) {
// Using binary search because the vector is sorted by offset
let found_index = game_stamps.binary_search_by_key(&offset, |s| s.offset).unwrap();
(game_stamps[found_index].score.home, game_stamps[found_index].score.away)
}