Day 1, puzzle 1
This commit is contained in:
commit
1a5b2ddfdd
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/target
|
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 = "aoc23"
|
||||
version = "0.1.0"
|
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
@ -0,0 +1,12 @@
|
||||
[package]
|
||||
name = "aoc23"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
[[bin]]
|
||||
name = "d1p1"
|
||||
path = "src/d1p1.rs"
|
28
src/d1p1.rs
Normal file
28
src/d1p1.rs
Normal file
@ -0,0 +1,28 @@
|
||||
use std::io;
|
||||
|
||||
fn main() {
|
||||
println!("What's the calorie list?");
|
||||
let lines = io::stdin().lines();
|
||||
let mut was_empty = false;
|
||||
let mut elves = vec![0];
|
||||
for line in lines {
|
||||
let line_s = line.unwrap();
|
||||
if line_s.is_empty() {
|
||||
if was_empty {
|
||||
break;
|
||||
}
|
||||
elves.push(0);
|
||||
was_empty = true;
|
||||
continue;
|
||||
} else {
|
||||
was_empty = false;
|
||||
}
|
||||
|
||||
let calories: u32 = line_s.parse().expect("Wanted a number");
|
||||
let prev_calories = elves.pop().unwrap();
|
||||
elves.push(prev_calories + calories);
|
||||
}
|
||||
|
||||
let max = elves.iter().max().unwrap();
|
||||
println!("The elf with the most calories is carrying {} cal", max);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user