From e8a36de2b493d499894634bf09aa1eabebfa520c Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 3 Dec 2021 16:36:25 +0100 Subject: [PATCH 1/2] 2020: day23: remove TODOs std::cmp::Ord::clamp can't really help in this situation, not sure what I had in mind --- aoc2020/src/day23.rs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/aoc2020/src/day23.rs b/aoc2020/src/day23.rs index cd27a66..5e3c626 100644 --- a/aoc2020/src/day23.rs +++ b/aoc2020/src/day23.rs @@ -71,8 +71,6 @@ impl CupCircle { // keep subtracting one until it finds a cup that wasn't just picked up. If at any point in // this process the value goes below the lowest value on any cup's label, it wraps around to // the highest value on any cup's label instead. - // - // TODO: use std::cmp::Ord::clamp when stabilized (Rust 1.50) let mut destination = if current > 1 { current - 1 } else { self.max() }; while removed_cups.contains(&destination) { destination = if destination > 1 { @@ -193,8 +191,6 @@ impl FastCupCircle { // keep subtracting one until it finds a cup that wasn't just picked up. If at any point in // this process the value goes below the lowest value on any cup's label, it wraps around to // the highest value on any cup's label instead. - // - // TODO: use std::cmp::Ord::clamp when stabilized (Rust 1.50) let mut destination = if self.current > 1 { self.current - 1 } else { From ebc5fe5425bd41bacf5021f38395a7b6db11ba70 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Fri, 3 Dec 2021 17:34:28 +0100 Subject: [PATCH 2/2] 2021: day02: use split_once --- aoc2021/src/day02.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/aoc2021/src/day02.rs b/aoc2021/src/day02.rs index 2bfc9c7..a65b4e1 100644 --- a/aoc2021/src/day02.rs +++ b/aoc2021/src/day02.rs @@ -69,10 +69,7 @@ impl std::str::FromStr for Command { type Err = anyhow::Error; fn from_str(s: &str) -> Result { - let mut split = s.split(' '); - - let word = split.next().context("couldn't find word in command")?; - let number = split.next().context("couldn't find number in command")?; + let (word, number) = s.split_once(' ').context("couldn't split command")?; let number = number.parse()?;