diff --git a/src/main.rs b/src/main.rs index cc0730c..5b40d29 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,32 @@ fn main() { } fn stati(s: &str) -> String { - s.into() + let mut t = + s.split(", ") + .map( + |m| m.split('|') + .map(|e| e.parse::().unwrap()) + .collect::>() + .chunks(3) + .map(|c| (c[0],c[1],c[2])) + .map(|(h,m,s)| h*3600 + m*60 + s) + .sum() + ) + .collect::>(); + + t.sort_unstable(); + + let (len, tot) = (t.len(), t.iter().sum::()); + let (avg, mid, rng) = (tot/len, len/2, t[len-1] - t[0]); + let med = if len % 2 == 1 { t[mid] } else { (t[mid-1] + t[mid]) / 2}; + + let hms = |i| { + format!("{:02}|{:02}|{:02}", i/3600, i%3600/60, i%60) + }; + + format!("Range: {} Average: {} Median: {}", + hms(rng), hms(avg), hms(med) + ) } #[cfg(test)]