Add data for course 1 assignment 4

This commit is contained in:
2020-11-27 12:14:35 -05:00
parent 83b973f577
commit f76f570d8b
3 changed files with 231 additions and 22 deletions

21
src/util.rs Normal file
View File

@@ -0,0 +1,21 @@
use std::fs::File;
use std::io;
use std::io::{BufRead, BufReader, Error, ErrorKind};
use std::vec::Vec;
pub fn read_to_vector(path: &str) -> Result<Vec<i64>, io::Error> {
let file = File::open(path)?;
let br = BufReader::new(file);
let mut v = Vec::new();
for line in br.lines() {
let line = line?;
let n = line
.trim()
.parse()
.map_err(|e| Error::new(ErrorKind::InvalidData, e))?;
v.push(n);
}
Ok(v)
}