This commit is contained in:
TriMill 2022-12-01 00:25:40 -05:00
parent 65fc6a9def
commit cb25f1c89c
7 changed files with 53 additions and 0 deletions

2
.gitignore vendored Normal file
View file

@ -0,0 +1,2 @@
/target
/input

7
Cargo.lock generated Normal file
View 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
View 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]

View file

@ -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.

16
examples/day01_1.rs Normal file
View 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
View 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
View file