This commit is contained in:
Joe Ardent 2022-12-04 11:58:25 -08:00
parent c2cd2efe3d
commit b2cfa5ca57

View file

@ -1,6 +1,7 @@
use aoc_runner_derive::{aoc as aoc_run, aoc_generator};
type Assignments = ((u32, u32), (u32, u32));
type TRange = (u32, u32);
type Assignments = (TRange, TRange);
#[aoc_generator(day4)]
fn parse_input(input: &str) -> Vec<Assignments> {
@ -36,15 +37,15 @@ fn part2(scheds: &[Assignments]) -> u32 {
out
}
fn get_range(r: &str) -> (u32, u32) {
fn get_range(r: &str) -> TRange {
let (lo, hi) = r.split_once('-').unwrap();
(lo.parse().unwrap(), hi.parse().unwrap())
}
fn contains(a: &(u32, u32), b: &(u32, u32)) -> bool {
fn contains(a: &TRange, b: &TRange) -> bool {
a.0 <= b.0 && b.1 <= a.1
}
fn overlaps(a: &(u32, u32), b: &(u32, u32)) -> bool {
fn overlaps(a: &TRange, b: &TRange) -> bool {
a.0 <= b.0 && b.0 <= a.1
}