use std::fs::File; use std::io::{self, BufRead}; use std::path::Path; use std::env; fn read_lines

(filename: P) -> io::Result>> where P: AsRef, { let file = File::open(filename)?; Ok(io::BufReader::new(file).lines()) } fn main() { let mut left_list: Vec = vec![]; let mut right_list: Vec = vec![]; let args: Vec<_> = env::args().collect(); if let Ok(lines) = read_lines(args[1].clone()) { for line in lines.flatten() { let parts = line.split(" ").collect::>(); let lnum = parts[0].parse::().unwrap(); let rnum = parts[1].parse::().unwrap(); left_list.push(lnum); right_list.push(rnum); } left_list.sort(); right_list.sort(); let mut sum = 0; for (i, left_n) in left_list.iter().enumerate() { let right_n = right_list[i]; println!("{} {} {}", i, left_n, right_n); sum += (left_n - right_n).abs(); } println!("{}", sum); } }