Compare commits

..

No commits in common. "cd250ddd352748660bcfd2ad79a91ed3595246d7" and "3d248900a33fd888877ad381f53076a82d7fa4c4" have entirely different histories.

2 changed files with 29 additions and 22 deletions

12
.gitignore vendored
View File

@ -1,11 +1,17 @@
**/.vscode **/.vscode
**/.idea **/.idea
**/input.txt
**/debug/ **/debug/
**/target/ **/target/
**/*rs.bk **/*rs.bk
**/calibration_document.txt
**/.vsidx **/.vsidx
**/.suo **/.suo
**/obj /CSharp/AdventOfCode/AdventOfCode/obj
**/bin /CSharp/AdventOfCode/AdventOfCode/bin
**/.vs /CSharp/AdventOfCode/.vs
/CSharp/AdventOfCode/DayOne/obj
/CSharp/AdventOfCode/DayOne/bin
/CSharp/AdventOfCode/DayTwo/obj
/CSharp/AdventOfCode/DayTwo/bin
*.txt *.txt

View File

@ -3,13 +3,11 @@ use std::fs;
fn main() { fn main() {
let contents = fs::read_to_string("input.txt").expect("Could not read the file"); let contents = fs::read_to_string("input.txt").expect("Could not read the file");
let first_total_calibration_value = first_impl(&contents); let first_total_calibration_value = first_impl(contents);
println!("The total value is: {first_total_calibration_value}"); println!("The total value is: {first_total_calibration_value}");
let second_total_calibration_value = second_impl(&contents);
println!("The second total value is: {second_total_calibration_value}")
} }
fn first_impl(contents: &String) -> i32 { fn first_impl(contents: String) -> i32 {
let mut total_calibration_value = 0; let mut total_calibration_value = 0;
for line in contents.split_whitespace() { for line in contents.split_whitespace() {
@ -32,19 +30,22 @@ fn first_impl(contents: &String) -> i32 {
} }
return total_calibration_value return total_calibration_value
} }
fn second_impl(contents: &String) -> i32 {
first_impl(&number_string_to_int(contents)) fn second_impl(contents: String) -> i32 {
return 0
} }
fn number_string_to_int(probable_string: &String) -> String{ fn number_string_to_int(probable_string: &String) -> Option<i32>{
probable_string.clone() match probable_string.as_str() {
.replace("one", "on1ne") "nine" => Some(9),
.replace("two", "tw2wo") "eight" => Some(8),
.replace("three", "thre3hree") "seven" => Some(7),
.replace("four","fou4our") "six" => Some(6),
.replace("five", "fiv5ive") "five" => Some(5),
.replace("six", "si6ix") "four" => Some(4),
.replace("seven", "seve7even") "three" => Some(3),
.replace("eight", "eigh8ight") "two" => Some(2),
.replace("nine", "nin9ine") "one" => Some(1),
_ => None,
}
} }