This commit is contained in:
LordMZTE 2021-12-05 00:21:28 +01:00
commit 35548b727d
6 changed files with 2058 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
Cargo.lock

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "aoc2021"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
libaoc = { path = "../libaoc/libaoc" }

2000
input/day1.txt Normal file

File diff suppressed because it is too large Load Diff

1
src/days.rs Normal file
View File

@ -0,0 +1 @@
pub mod day1;

36
src/days/day1.rs Normal file
View File

@ -0,0 +1,36 @@
#![libaoc::day(1, "../../input/day1.txt")]
use libaoc::miette::{IntoDiagnostic, Result};
fn part1() -> Result<()> {
let input = input_parsed()?;
let count = input
.iter()
.zip(input.iter().skip(1).chain(Some(&0)))
.filter(|(a, b)| a < b)
.count();
println!("{}", count);
Ok(())
}
fn part2() -> Result<()> {
let input = input_parsed()?;
let count = input
.windows(3)
.zip(input[1..].windows(3).chain(Some(&[0, 0, 0][..])))
.filter(|(a, b)| a.iter().sum::<u32>() < b.iter().sum::<u32>())
.count();
println!("{}", count);
Ok(())
}
fn input_parsed() -> Result<Vec<u32>> {
INPUT
.lines()
.map(|l| l.parse::<u32>().into_diagnostic())
.collect()
}

10
src/main.rs Normal file
View File

@ -0,0 +1,10 @@
#![feature(custom_inner_attributes)]
#![feature(proc_macro_hygiene)]
mod days;
use days::*;
fn main() -> libaoc::miette::Result<()> {
libaoc::run_days!(
day1
)
}