day 01
This commit is contained in:
parent
65fc6a9def
commit
cb25f1c89c
7 changed files with 53 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
/input
|
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 = "aoc2022"
|
||||||
|
version = "0.1.0"
|
8
Cargo.toml
Normal file
8
Cargo.toml
Normal file
|
@ -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
|
# 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.
|
||||||
|
|
16
examples/day01_1.rs
Normal file
16
examples/day01_1.rs
Normal file
|
@ -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(())
|
||||||
|
}
|
18
examples/day01_2.rs
Normal file
18
examples/day01_2.rs
Normal file
|
@ -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(())
|
||||||
|
}
|
0
src/lib.rs
Normal file
0
src/lib.rs
Normal file
Loading…
Reference in a new issue