From 80877a69784fe06ba710decaef8bdd8e0c8089e3 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 5 Dec 2018 12:43:03 -0800 Subject: [PATCH] [2018][rust][1] move from lib to bin --- 2018/rust/src/{ => bin}/day_01.rs | 17 +++++++++++++++-- 2018/rust/src/main.rs | 5 ----- 2 files changed, 15 insertions(+), 7 deletions(-) rename 2018/rust/src/{ => bin}/day_01.rs (76%) delete mode 100644 2018/rust/src/main.rs diff --git a/2018/rust/src/day_01.rs b/2018/rust/src/bin/day_01.rs similarity index 76% rename from 2018/rust/src/day_01.rs rename to 2018/rust/src/bin/day_01.rs index 8c6878d..658d5c7 100644 --- a/2018/rust/src/day_01.rs +++ b/2018/rust/src/bin/day_01.rs @@ -1,6 +1,19 @@ use std::collections::HashMap; +use std::error::Error; +use std::io::{self, Read}; -pub fn solve_0(input: &str, delimiter: &str) -> String { +fn main() -> Result<(), Box> { + let mut input = String::new(); + io::stdin().read_to_string(&mut input)?; + + let output = solve_1(&input, "\n"); + println!("{}", output); + + Ok(()) +} + +#[allow(dead_code)] +fn solve_0(input: &str, delimiter: &str) -> String { let sum: i32 = input .trim() .split(delimiter) @@ -14,7 +27,7 @@ fn test_solve_0() { assert_eq!(solve_0("+1, -2, +3, +1", ", "), "3"); } -pub fn solve_1(input: &str, delimiter: &str) -> String { +fn solve_1(input: &str, delimiter: &str) -> String { vec![0 as i32] // Start with 0 frequency .into_iter() .chain( diff --git a/2018/rust/src/main.rs b/2018/rust/src/main.rs deleted file mode 100644 index 00bcf0b..0000000 --- a/2018/rust/src/main.rs +++ /dev/null @@ -1,5 +0,0 @@ -use std::io::{self, Read}; - -mod day_01; - -fn main() {}