parent
7510bc2f59
commit
4e36ed6462
|
@ -1,9 +1,30 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
"common",
|
"common",
|
||||||
"day-1_calorie_counting",
|
"day-1",
|
||||||
"day-2_rock_paper_scissors",
|
"day-2",
|
||||||
"day-3_rucksack_reorganization",
|
"day-3",
|
||||||
|
"day-4",
|
||||||
|
"day-5",
|
||||||
|
# "day-6",
|
||||||
|
# "day-7",
|
||||||
|
# "day-8",
|
||||||
|
# "day-9",
|
||||||
|
# "day-10",
|
||||||
|
# "day-11",
|
||||||
|
# "day-12",
|
||||||
|
# "day-13",
|
||||||
|
# "day-14",
|
||||||
|
# "day-15",
|
||||||
|
# "day-16",
|
||||||
|
# "day-17",
|
||||||
|
# "day-18",
|
||||||
|
# "day-19",
|
||||||
|
# "day-20",
|
||||||
|
# "day-21",
|
||||||
|
# "day-22",
|
||||||
|
# "day-23",
|
||||||
|
# "day-24",
|
||||||
]
|
]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
Before Width: | Height: | Size: 181 KiB After Width: | Height: | Size: 181 KiB |
|
@ -0,0 +1,22 @@
|
||||||
|
[package]
|
||||||
|
name = "camp_cleanup"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "lib"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "camp_cleanup"
|
||||||
|
path = "src/bin.rs"
|
||||||
|
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
common = {path = "../common/"}
|
||||||
|
|
||||||
|
clap = {version = "4.0.22", features = ["derive"]}
|
||||||
|
tracing = "0.1"
|
||||||
|
tracing-subscriber = {version = "0.3.16", features = ["env-filter"]}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,17 @@
|
||||||
|
use common::cli::Cli;
|
||||||
|
use common::read_file;
|
||||||
|
use lib::{task_a, task_b};
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
pub fn main() {
|
||||||
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
|
let args = Cli::parse();
|
||||||
|
debug!("Args: {:?}", args);
|
||||||
|
|
||||||
|
let content = read_file(&args.input).unwrap();
|
||||||
|
println!("Result (a): {}", task_a(&content));
|
||||||
|
println!("Result (b): {}", task_b(&content));
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
fn boundries(line: &str) -> Vec<Vec<u64>> {
|
||||||
|
line.split(',')
|
||||||
|
.map(|s| s.split('-').map(|t| t.parse().unwrap()).collect())
|
||||||
|
.collect::<Vec<Vec<u64>>>()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn task_a(input: &str) -> u64 {
|
||||||
|
let result = input
|
||||||
|
.trim()
|
||||||
|
.lines()
|
||||||
|
.map(boundries)
|
||||||
|
.filter(|r| {
|
||||||
|
(r[0][0] >= r[1][0] && r[0][1] <= r[1][1]) || (r[1][0] >= r[0][0] && r[1][1] <= r[0][1])
|
||||||
|
})
|
||||||
|
.count();
|
||||||
|
(result as u16).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn task_b(input: &str) -> u64 {
|
||||||
|
let result = input
|
||||||
|
.trim()
|
||||||
|
.lines()
|
||||||
|
.map(boundries)
|
||||||
|
.filter(|r| {
|
||||||
|
println!("{:?}", r[0].clone().min(r[1].clone()));
|
||||||
|
println!("{:?}", r[0].clone().max(r[1].clone()));
|
||||||
|
true
|
||||||
|
})
|
||||||
|
.count();
|
||||||
|
(result as u16).into()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
const TEST_INPUT: &str = "2-4,6-8\n2-3,4-5\n5-7,7-9\n2-8,3-7\n6-6,4-6\n2-6,4-8";
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_task_a() {
|
||||||
|
let result = task_a(TEST_INPUT);
|
||||||
|
let expected = 2;
|
||||||
|
assert_eq!(result, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_task_b() {
|
||||||
|
let result = task_b(TEST_INPUT);
|
||||||
|
let expected = 2;
|
||||||
|
assert_eq!(result, expected);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
[package]
|
||||||
|
name = "supply_stacks"
|
||||||
|
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,14 @@
|
||||||
|
pub fn add(left: usize, right: usize) -> usize {
|
||||||
|
left + right
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
let result = add(2, 2);
|
||||||
|
assert_eq!(result, 4);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue