This file contains hidden or 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
| static RE: OnceLock<Regex> = OnceLock::new(); | |
| fn process_input(input: &str) -> Vec<(i64, i64)> { | |
| let re = RE.get_or_init(|| Regex::new(r"(\d+)\s*").unwrap()); | |
| let r: Vec<Vec<i64>> = input | |
| .trim_end() | |
| .lines() | |
| .map(|l| { | |
| re.captures_iter(l) |
This file contains hidden or 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
| #[derive(Debug)] | |
| struct Rules { | |
| seeds: Vec<i64>, | |
| maps: Vec<Vec<(i64, i64, i64)>>, | |
| } | |
| impl Rules { | |
| fn compute_next_location(n: i64, map: &(i64, i64, i64)) -> Option<i64> { | |
| let (dest_range, source_range, range_length) = *map; |
This file contains hidden or 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
| #[derive(Debug)] | |
| struct Game { | |
| winning: Vec<String>, | |
| rolled: Vec<String>, | |
| } | |
| impl From<&str> for Game { | |
| fn from(value: &str) -> Self { | |
| let colon_index = value.find(':').unwrap(); |
This file contains hidden or 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 process_input(input: &str) -> Vec<Vec<char>> { | |
| input | |
| .trim_end() | |
| .lines() | |
| .map(|l| l.chars().collect()) | |
| .collect() | |
| } | |
| fn is_symbol(c: char) -> bool { | |
| !c.is_alphanumeric() && c != '.' |
This file contains hidden or 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
| struct Game { | |
| game_index: i32, | |
| subsets: Vec<(i32, i32, i32)>, | |
| } | |
| impl TryFrom<&str> for Game { | |
| type Error = anyhow::Error; | |
| fn try_from(value: &str) -> Result<Self, Self::Error> { | |
| let mut subsets = vec![]; |
This file contains hidden or 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 compute_result(input: &str) -> u32 { | |
| input | |
| .replace(char::is_alphabetic, "") | |
| .lines() | |
| .map(|l| { | |
| let mut iter = l.chars().flat_map(|c| char::to_digit(c, 10)).peekable(); | |
| let first = *iter.peek().expect("no first numerical character"); | |
| let last = iter.last().expect("no last numerical character"); |
This file contains hidden or 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 find_side_digit(digits: &[&str], line: &str, left: bool) -> usize { | |
| let map = digits.iter().enumerate().flat_map(|(i, d)| { | |
| if left { | |
| if let Some(min_index) = line.find(d) { | |
| Some((min_index, i % 9 + 1)) | |
| } else { | |
| None | |
| } | |
| } else { | |
| if let Some(max_index) = line.rfind(d) { |
This file contains hidden or 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
| @group(0) @binding(0) var<storage, read_write> moon_height_data: MoonHeightData; | |
| fn smooth_min(a: f32, b: f32, t: f32) -> f32 { | |
| let h: f32 = clamp(0.5 + 0.5 * (b - a) / t, 0.0, 1.0); | |
| return mix(b, a, h) - t * h * (1.0 - h); | |
| } | |
| fn smooth_max(a: f32, b: f32, t: f32) -> f32 { | |
| return smooth_min(a, b, -t); |
This file contains hidden or 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 sum(vector: &mut Vec<i32>) -> i32 { | |
| let mut sum = 0; | |
| vector.iter_mut().map(|e| e.add(1)); | |
| for item in vector { | |
| sum = sum + *item | |
| } | |
| sum |
This file contains hidden or 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 sum(vector: &Vec<i32>) -> i32 { | |
| let mut sum = 0; | |
| // vector.iter_mut().map(|e| e.add(1)); | |
| // ERROR: cannot borrow `*vector` as mutable, as it is behind a `&` reference | |
| for item in vector { | |
| sum = sum + item | |
| } |
NewerOlder