mirror of
https://github.com/peter-tanner/advent-of-code-2022.git
synced 2024-11-30 06:10:22 +08:00
day 1 part 1 & 2
This commit is contained in:
parent
4e7b2ce48b
commit
a6894ee3be
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -13,4 +13,6 @@ Cargo.lock
|
|||
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||
*.pdb
|
||||
|
||||
.vscode/
|
||||
.vscode/
|
||||
|
||||
input
|
|
@ -1,3 +1,20 @@
|
|||
use std::fs;
|
||||
|
||||
const PATH: &str = "src/input";
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
let data = fs::read_to_string(PATH).expect("Error reading file");
|
||||
let mut cals_list: Vec<u32> = Vec::new();
|
||||
let mut cals: u32 = 0;
|
||||
for line in data.split("\n") {
|
||||
if line.len() == 0 {
|
||||
cals_list.push(cals);
|
||||
cals = 0;
|
||||
} else {
|
||||
cals += line.parse::<u32>().unwrap();
|
||||
}
|
||||
}
|
||||
cals_list.sort_by(|a, b| b.cmp(a));
|
||||
println!("PART 1: {}", cals_list[0]);
|
||||
println!("PART 2: {}", cals_list[0] + cals_list[1] + cals_list[2]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user