use std::io::{BufRead, BufReader}; use std::fs::File; fn main (){ // let filename = "../1/input_example.txt"; let filename = "../1/input.txt"; let file = BufReader::new(File::open(filename).expect("Unable to open file")); let mut accum: u32 = 0; let mut list1: Vec = vec![]; let mut list2: Vec = vec![]; for line in file.lines() { let wline = line.unwrap(); let nums: Vec<&str> = wline.split(' ') .filter(|&x| !x.is_empty()) .collect(); list1.push(nums[0].parse().unwrap()); list2.push(nums[1].parse().unwrap()); } list1.sort(); list2.sort(); let zlist = list1.into_iter().zip(list2); for t in zlist { accum += t.0.abs_diff(t.1); } println!("{}", accum); }