Compare commits
2 Commits
3d248900a3
...
cd250ddd35
| Author | SHA1 | Date |
|---|---|---|
|
|
cd250ddd35 | |
|
|
8ef1350090 |
|
|
@ -1,17 +1,11 @@
|
|||
**/.vscode
|
||||
**/.idea
|
||||
**/input.txt
|
||||
**/debug/
|
||||
**/target/
|
||||
**/*rs.bk
|
||||
**/calibration_document.txt
|
||||
**/.vsidx
|
||||
**/.suo
|
||||
/CSharp/AdventOfCode/AdventOfCode/obj
|
||||
/CSharp/AdventOfCode/AdventOfCode/bin
|
||||
/CSharp/AdventOfCode/.vs
|
||||
/CSharp/AdventOfCode/DayOne/obj
|
||||
/CSharp/AdventOfCode/DayOne/bin
|
||||
/CSharp/AdventOfCode/DayTwo/obj
|
||||
/CSharp/AdventOfCode/DayTwo/bin
|
||||
**/obj
|
||||
**/bin
|
||||
**/.vs
|
||||
*.txt
|
||||
|
|
@ -3,11 +3,13 @@ use std::fs;
|
|||
fn main() {
|
||||
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}");
|
||||
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;
|
||||
|
||||
for line in contents.split_whitespace() {
|
||||
|
|
@ -30,22 +32,19 @@ fn first_impl(contents: String) -> i32 {
|
|||
}
|
||||
return total_calibration_value
|
||||
}
|
||||
|
||||
fn second_impl(contents: String) -> i32 {
|
||||
return 0
|
||||
fn second_impl(contents: &String) -> i32 {
|
||||
first_impl(&number_string_to_int(contents))
|
||||
}
|
||||
|
||||
fn number_string_to_int(probable_string: &String) -> Option<i32>{
|
||||
match probable_string.as_str() {
|
||||
"nine" => Some(9),
|
||||
"eight" => Some(8),
|
||||
"seven" => Some(7),
|
||||
"six" => Some(6),
|
||||
"five" => Some(5),
|
||||
"four" => Some(4),
|
||||
"three" => Some(3),
|
||||
"two" => Some(2),
|
||||
"one" => Some(1),
|
||||
_ => None,
|
||||
}
|
||||
fn number_string_to_int(probable_string: &String) -> String{
|
||||
probable_string.clone()
|
||||
.replace("one", "on1ne")
|
||||
.replace("two", "tw2wo")
|
||||
.replace("three", "thre3hree")
|
||||
.replace("four","fou4our")
|
||||
.replace("five", "fiv5ive")
|
||||
.replace("six", "si6ix")
|
||||
.replace("seven", "seve7even")
|
||||
.replace("eight", "eigh8ight")
|
||||
.replace("nine", "nin9ine")
|
||||
}
|
||||
Loading…
Reference in New Issue