diff --git a/one/Cargo.toml b/one/Cargo.toml index dcf4350..342a5c1 100644 --- a/one/Cargo.toml +++ b/one/Cargo.toml @@ -3,6 +3,14 @@ name = "one" version = "0.1.0" edition = "2021" +[[bin]] +name = "pone" +path = "src/one.rs" + +[[bin]] +name = "ptwo" +path = "src/two.rs" + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/one/output b/one/output-one similarity index 100% rename from one/output rename to one/output-one diff --git a/one/output-two b/one/output-two new file mode 100644 index 0000000..c2b86cf --- /dev/null +++ b/one/output-two @@ -0,0 +1 @@ +54418 \ No newline at end of file diff --git a/one/src/main.rs b/one/src/one.rs similarity index 100% rename from one/src/main.rs rename to one/src/one.rs diff --git a/one/src/two.rs b/one/src/two.rs new file mode 100644 index 0000000..c548c01 --- /dev/null +++ b/one/src/two.rs @@ -0,0 +1,36 @@ +use std::io::{self, Read}; + +fn main() { + let mut buf = String::new(); + io::stdin().read_to_string(&mut buf).unwrap(); + + let buf = buf.replace("twone", "twoone"); + let buf = buf.replace("threeight", "threeeight"); + let buf = buf.replace("oneight", "oneeight"); + let buf = buf.replace("eightwo", "eighttwo"); + let buf = buf.replace("eighthree", "eightthree"); + let buf = buf.replace("nineight", "nineeight"); + let buf = buf.replace("one", "1"); + let buf = buf.replace("two", "2"); + let buf = buf.replace("three", "3"); + let buf = buf.replace("four", "4"); + let buf = buf.replace("five", "5"); + let buf = buf.replace("six", "6"); + let buf = buf.replace("seven", "7"); + let buf = buf.replace("eight", "8"); + let buf = buf.replace("nine", "9"); + + let lines: Vec = buf.lines().map(ToOwned::to_owned).collect(); + + let answer: Result = lines + .into_iter() + .map(|l| l.chars().filter(char::is_ascii_digit).collect()) + .map(|s: String| [s.chars().next().unwrap(), s.chars().last().unwrap()].to_owned()) + .map(String::from_iter) + .map(|s| s.parse::()) + .sum(); + + let answer = answer.unwrap(); + + print!("{answer}"); +}