Last active
December 2, 2023 00:00
-
-
Save calam1/9e0d5f633297e218fc65aad4c48810f8 to your computer and use it in GitHub Desktop.
AOC Day 01a Rust solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let re = regex::Regex::new(r"[A-Za-z]").unwrap(); | |
println!( | |
"{:?}", | |
include_str!("../input.txt") | |
.lines() | |
.map(|s| re.split(s).filter(|s| !s.is_empty())) | |
.map(|s| { | |
s.into_iter() | |
.flat_map(|s| { | |
if s.len() > 1 { | |
s.chars().map(|c| c.to_string()).collect::<Vec<String>>() | |
} else { | |
vec![s.to_string()] | |
} | |
}) | |
.collect::<Vec<String>>() | |
}) | |
.map(|s| { | |
let mut v = Vec::new(); | |
v.push(s[0].to_string()); | |
v.push(s[s.len() - 1].to_string()); | |
v.join("") | |
}) | |
.map(|s| { s.parse::<u32>().unwrap() }) | |
.sum::<u32>() | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment