Use tuple_map to map tuples

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

View File

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