finish day 1
This commit is contained in:
commit
69ff24d2cd
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
/target
|
||||
/.idea/
|
||||
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "advent-of-code-2022"
|
||||
version = "0.1.0"
|
||||
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "advent-of-code-2022"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
2267
input/day_1.txt
Normal file
2267
input/day_1.txt
Normal file
File diff suppressed because it is too large
Load Diff
23
src/day_1.rs
Normal file
23
src/day_1.rs
Normal file
@ -0,0 +1,23 @@
|
||||
use std::fs;
|
||||
|
||||
pub fn day_1() -> String {
|
||||
let input = fs::read_to_string("input/day_1.txt").unwrap();
|
||||
|
||||
let elves: Vec<&str> = input.split("\n\n").collect();
|
||||
|
||||
let mut highest_calorie_count: u64 = 0;
|
||||
|
||||
for meals in elves.iter() {
|
||||
let mut elf_calorie_count= 0;
|
||||
|
||||
for meal in meals.split_whitespace() {
|
||||
elf_calorie_count += meal.parse().unwrap_or(0);
|
||||
}
|
||||
|
||||
if elf_calorie_count > highest_calorie_count {
|
||||
highest_calorie_count = elf_calorie_count;
|
||||
}
|
||||
}
|
||||
|
||||
format!("{highest_calorie_count}")
|
||||
}
|
||||
5
src/main.rs
Normal file
5
src/main.rs
Normal file
@ -0,0 +1,5 @@
|
||||
mod day_1;
|
||||
|
||||
fn main() {
|
||||
println!("{}", day_1::day_1());
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user