add library to load data
This commit is contained in:
+1
-17
@@ -1,4 +1,4 @@
|
||||
use std::{fs::File, io::Read};
|
||||
use util::get_data;
|
||||
|
||||
fn main() {
|
||||
let word_numbers: Vec<String> = vec![
|
||||
@@ -123,22 +123,6 @@ fn get_first_digit(word_numbers: &Vec<String>, line: &String) -> char {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_data(path: &str) -> Vec<String> {
|
||||
let mut data = match File::open(path) {
|
||||
Ok(file) => file,
|
||||
Err(err) => panic!("failed to read the data file: {:?}", err),
|
||||
};
|
||||
|
||||
let mut content = String::new();
|
||||
data.read_to_string(&mut content)
|
||||
.ok()
|
||||
.expect("failed to parse file");
|
||||
|
||||
let lines: Vec<String> = content.split("\n").map(|l| l.to_string()).collect();
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
fn get_digit_from_str(word: &str) -> char {
|
||||
match word {
|
||||
"zero" => return '0',
|
||||
|
||||
Reference in New Issue
Block a user