Demonstrate solving the first problems from 2021
This commit is contained in:
parent
29d691ce95
commit
a014b25947
|
@ -1 +1,2 @@
|
|||
.direnv
|
||||
target
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "problems"
|
||||
version = "0.1.0"
|
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "problems"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
|
@ -0,0 +1,10 @@
|
|||
199
|
||||
200
|
||||
208
|
||||
210
|
||||
200
|
||||
207
|
||||
240
|
||||
269
|
||||
260
|
||||
263
|
|
@ -0,0 +1,25 @@
|
|||
const PART1: &str = include_str!("../data/day1a.txt");
|
||||
|
||||
pub fn part1() -> String {
|
||||
let lines = PART1.lines();
|
||||
|
||||
let depths: Vec<i32> = lines.map(|l| l.parse::<i32>().unwrap()).collect();
|
||||
|
||||
let depths_a = depths.iter();
|
||||
let depths_b = depths.iter().skip(1);
|
||||
let depth_cmp = depths_a.zip(depths_b);
|
||||
|
||||
let increases = depth_cmp.fold(0, |cur, (a, b)| {
|
||||
println!("{} < {}? {}", a, b, a < b);
|
||||
if a < b {
|
||||
cur + 1
|
||||
} else {
|
||||
cur
|
||||
}
|
||||
});
|
||||
format!("{}", increases)
|
||||
}
|
||||
|
||||
pub fn part2() -> String {
|
||||
"no response".to_owned()
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
mod day1;
|
||||
|
||||
fn main() {
|
||||
let day = std::env::args().skip(1).next();
|
||||
println!("day: {:?}", day);
|
||||
|
||||
let result = match day.as_ref().map(|v| v.as_ref()) {
|
||||
Some("day1a") => day1::part1(),
|
||||
Some("day1b") => day1::part2(),
|
||||
_ => panic!("unrecognized day"),
|
||||
};
|
||||
|
||||
println!("{:?} Result: {}", day, result);
|
||||
}
|
Loading…
Reference in New Issue