Use tuple_map to map tuples

This commit is contained in:
Max Nuding 2022-12-04 08:15:37 +00:00
parent 3bd486af95
commit ab92541119
3 changed files with 11 additions and 8 deletions

7
Cargo.lock generated
View File

@ -27,6 +27,7 @@ dependencies = [
"chrono", "chrono",
"itertools", "itertools",
"regex", "regex",
"tuple-map",
] ]
[[package]] [[package]]
@ -303,6 +304,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "tuple-map"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23d5919d7121237af683b7fa982450597b1eaa2643e597aec3b519e4e5ab3d62"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.5" version = "1.0.5"

View File

@ -9,6 +9,7 @@ edition = "2021"
chrono = "0.4.23" chrono = "0.4.23"
itertools = "0.10.5" itertools = "0.10.5"
regex = "1.7.0" regex = "1.7.0"
tuple-map = "0.4.0"
[features] [features]
default = ["part1", "part2", "today"] default = ["part1", "part2", "today"]

View File

@ -1,10 +1,8 @@
use crate::read; use crate::read;
use tuple_map::*;
fn get_ranges(elf: &str) -> std::ops::RangeInclusive<i32> { fn get_ranges(elf: &str) -> std::ops::RangeInclusive<i32> {
let r = elf let r = elf.split_once('-').unwrap().map(|e| e.parse().unwrap());
.split_once('-')
.map(|e| (e.0.parse().unwrap(), e.1.parse().unwrap()))
.unwrap();
r.0..=r.1 r.0..=r.1
} }
@ -13,10 +11,7 @@ pub fn run() {
let lines = input let lines = input
.lines() .lines()
.map(|l| { .map(|l| l.split_once(',').unwrap().map(get_ranges))
let pairs = l.split_once(',').unwrap();
(get_ranges(pairs.0), get_ranges(pairs.1))
})
.collect::<Vec<_>>(); .collect::<Vec<_>>();
#[cfg(feature = "part1")] #[cfg(feature = "part1")]
{ {