Browse Source

function ready for submission

master
Jim Infield 3 years ago
parent
commit
8024399dee
  1. 27
      src/main.rs

27
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::<usize>().unwrap())
.collect::<Vec<usize>>()
.chunks(3)
.map(|c| (c[0],c[1],c[2]))
.map(|(h,m,s)| h*3600 + m*60 + s)
.sum()
)
.collect::<Vec<usize>>();
t.sort_unstable();
let (len, tot) = (t.len(), t.iter().sum::<usize>());
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)]

Loading…
Cancel
Save