day 01
parent
65fc6a9def
commit
cb25f1c89c
@ -0,0 +1,2 @@
|
||||
/target
|
||||
/input
|
@ -0,0 +1,7 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aoc2022"
|
||||
version = "0.1.0"
|
@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "aoc2022"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
@ -1,3 +1,5 @@
|
||||
# Advent of Code 2022
|
||||
|
||||
WARNING: ADVENT OF CODE SPOILERS AHEAD
|
||||
|
||||
solutions located in the `examples` directory. run with `cargo r --example=day##_#.rs`. input is given via stdin.
|
||||
|
@ -0,0 +1,16 @@
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let lines = std::io::stdin().lines();
|
||||
let mut max = 0;
|
||||
let mut elf = 0;
|
||||
for line in lines {
|
||||
let line = line?;
|
||||
if line.trim().is_empty() {
|
||||
max = max.max(elf);
|
||||
elf = 0;
|
||||
} else {
|
||||
elf += line.parse::<i32>()?;
|
||||
}
|
||||
}
|
||||
println!("{}", max);
|
||||
Ok(())
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let lines = std::io::stdin().lines();
|
||||
let mut elves = Vec::new();
|
||||
let mut elf = 0;
|
||||
for line in lines {
|
||||
let line = line?;
|
||||
if line.trim().is_empty() {
|
||||
elves.push(elf);
|
||||
elf = 0;
|
||||
} else {
|
||||
elf += line.parse::<i32>()?;
|
||||
}
|
||||
}
|
||||
elves.sort();
|
||||
elves.reverse();
|
||||
println!("{}", elves[0] + elves[1] + elves[2]);
|
||||
Ok(())
|
||||
}
|
Loading…
Reference in New Issue