Improve Day 22 Task 1

This commit is contained in:
Aadi Desai 2023-12-23 00:30:07 +00:00
parent a1d50f0948
commit db833507ef
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM

View file

@ -7,17 +7,11 @@ pub(crate) fn router() -> Router {
} }
async fn integers(nums: String) -> Result<impl IntoResponse, StatusCode> { async fn integers(nums: String) -> Result<impl IntoResponse, StatusCode> {
let mut nums = nums nums.lines()
.lines() .map(|s| s.parse::<u64>())
.map(|s| s.parse::<u64>().expect("All lines should be valid u64s")) .try_fold(0u64, |acc, n| n.map(|n| acc ^ n))
.collect::<Vec<_>>(); .map(|n| "🎁".repeat(n as usize))
nums.sort_unstable(); .map_err(|_| StatusCode::BAD_REQUEST)
for i in (0..nums.len()).step_by(2) {
if i == (nums.len() - 1) || nums[i] != nums[i + 1] {
return Ok("🎁".repeat(nums[i] as usize));
}
}
Err(StatusCode::BAD_REQUEST)
} }
async fn rocket(input: String) -> Result<impl IntoResponse, StatusCode> { async fn rocket(input: String) -> Result<impl IntoResponse, StatusCode> {