From a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 Mon Sep 17 00:00:00 2001 From: Jack Sangdahl Date: Fri, 27 Jun 2025 12:23:02 -0600 Subject: chore: remove old cpp and rust solutions --- other/single_threaded_cpu.rs | 59 -------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 other/single_threaded_cpu.rs (limited to 'other/single_threaded_cpu.rs') diff --git a/other/single_threaded_cpu.rs b/other/single_threaded_cpu.rs deleted file mode 100644 index 4defcb7..0000000 --- a/other/single_threaded_cpu.rs +++ /dev/null @@ -1,59 +0,0 @@ -use std::collections::BinaryHeap; -use std::cmp::Ordering; -struct Solution; -#[derive(PartialEq, Eq, Copy, Clone)] -struct Task { - pub enqueue_time: i32, - pub processing_time: i32, - pub initial_idx: usize -} - -impl PartialOrd for Task { - fn partial_cmp(&self, other: &Self) -> Option { - if other.processing_time == self.processing_time { - return Some(other.initial_idx.cmp(&self.initial_idx)); - } - Some(other.processing_time.cmp(&self.processing_time)) - } -} - -impl Ord for Task { - fn cmp(&self, other: &Self) -> Ordering { - if other.processing_time == self.processing_time { - return other.initial_idx.cmp(&self.initial_idx); - } - other.processing_time.cmp(&self.processing_time) - } -} - -impl Solution { - pub fn get_order(tasks: Vec>) -> Vec { - let mut tasks = tasks.into_iter().enumerate().map(|(idx, task)| { - Task { - enqueue_time: task[0], - processing_time: task[1], - initial_idx: idx - } - }).collect::>(); - let (mut output, mut current_time) = (vec![], 0); - let mut available_tasks: BinaryHeap = BinaryHeap::new(); - while tasks.len() > 0 || available_tasks.len() > 0 { - while tasks.len() > 0 && tasks[tasks.len() - 1].enqueue_time <= current_time { - let task = tasks.pop().unwrap(); - available_tasks.push(task); - } - if let Some(task) = available_tasks.pop() { - output.push(task.initial_idx as i32); - current_time += task.processing_time; - } else { - current_time = tasks[tasks.len() - 1].enqueue_time; - } - } - output - } -} - -fn main() { - let tasks = vec![vec![1,2],vec![2,4],vec![3,2],vec![4,1]]; - print!("{:?}", Solution::get_order(tasks)); -} -- cgit v1.2.3