Use tuple_map to map tuples
This commit is contained in:
parent
3bd486af95
commit
ab92541119
7
Cargo.lock
generated
7
Cargo.lock
generated
@ -27,6 +27,7 @@ dependencies = [
|
||||
"chrono",
|
||||
"itertools",
|
||||
"regex",
|
||||
"tuple-map",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -303,6 +304,12 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tuple-map"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23d5919d7121237af683b7fa982450597b1eaa2643e597aec3b519e4e5ab3d62"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.5"
|
||||
|
@ -9,6 +9,7 @@ edition = "2021"
|
||||
chrono = "0.4.23"
|
||||
itertools = "0.10.5"
|
||||
regex = "1.7.0"
|
||||
tuple-map = "0.4.0"
|
||||
|
||||
[features]
|
||||
default = ["part1", "part2", "today"]
|
||||
|
@ -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")]
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user