add library to load data
This commit is contained in:
Generated
+7
@@ -5,3 +5,10 @@ version = 3
|
||||
[[package]]
|
||||
name = "day1"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "util"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -6,3 +6,4 @@ edition = "2021"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
util = { path = "../util/" }
|
||||
|
||||
+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',
|
||||
|
||||
Binary file not shown.
@@ -1 +1 @@
|
||||
/home/mimu/projects/aoc2023/day1/target/debug/day1: /home/mimu/projects/aoc2023/day1/src/main.rs
|
||||
/home/mimu/projects/aoc2023/day1/target/debug/day1: /home/mimu/projects/aoc2023/day1/src/main.rs /home/mimu/projects/aoc2023/util/src/lib.rs
|
||||
|
||||
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Reference in New Issue
Block a user