init
This commit is contained in:
commit
35548b727d
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
/target
|
||||||
|
Cargo.lock
|
9
Cargo.toml
Normal file
9
Cargo.toml
Normal 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
2000
input/day1.txt
Normal file
File diff suppressed because it is too large
Load diff
1
src/days.rs
Normal file
1
src/days.rs
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pub mod day1;
|
36
src/days/day1.rs
Normal file
36
src/days/day1.rs
Normal 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
10
src/main.rs
Normal 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
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in a new issue