Advent of Code solutions
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Linting

Ben C 731a2bea ffd2a3fd

+48 -54
+6 -6
core/src/bootstrap.rs
··· 86 86 fn make_lib(folder: &Path, year: &str) { 87 87 let lib_path = folder.join("lib.rs"); 88 88 89 - let contents = YEAR_TEMPLATE.replace("{year}", &year); 89 + let contents = YEAR_TEMPLATE.replace("{year}", year); 90 90 91 91 std::fs::write(lib_path, contents).unwrap(); 92 92 } ··· 94 94 fn make_main(folder: &Path, year: &str) { 95 95 let main_path = folder.join("main.rs"); 96 96 97 - let contents = RUNNER_TEMPLATE.replace("{year}", &year); 97 + let contents = RUNNER_TEMPLATE.replace("{year}", year); 98 98 99 99 std::fs::write(main_path, contents).unwrap(); 100 100 } ··· 106 106 107 107 make_days(&src_path); 108 108 make_examples(&src_path); 109 - make_lib(&src_path, &year); 110 - make_main(&src_path, &year); 109 + make_lib(&src_path, year); 110 + make_main(&src_path, year); 111 111 } 112 112 113 113 fn make_cargo(folder: &Path, year: &str) { 114 114 let cargo_path = folder.join("Cargo.toml"); 115 115 116 - let contents = CARGO_TEMPLATE.replace("{year}", &year); 116 + let contents = CARGO_TEMPLATE.replace("{year}", year); 117 117 118 118 std::fs::write(cargo_path, contents).unwrap(); 119 119 } ··· 131 131 .get(1) 132 132 .unwrap() 133 133 .as_str() 134 - .split(",") 134 + .split(',') 135 135 .map(|s| s.parse::<usize>().unwrap()) 136 136 .collect::<Vec<_>>(); 137 137
+2 -2
core/src/parser.rs
··· 68 68 pub fn get_dp_and_input() -> (DP, Option<String>) { 69 69 let mut args = args().skip(1); 70 70 71 - let dp = args.next().map(|s| DP::parse(&s.trim())).unwrap_or(DP_ALL); 71 + let dp = args.next().map(|s| DP::parse(s.trim())).unwrap_or(DP_ALL); 72 72 73 73 let input = args.next().map(|s| s.trim().to_string()).map(|i| { 74 74 if i == "-" { ··· 88 88 pub fn get_ydp_and_input(args: Vec<String>) -> (YDP, Option<String>) { 89 89 let mut args = args.into_iter(); 90 90 91 - let ydp = args.next().map(|s| YDP::parse(&s.trim())).unwrap_or(YDP { 91 + let ydp = args.next().map(|s| YDP::parse(s.trim())).unwrap_or(YDP { 92 92 year: Selection::All, 93 93 day: Selection::All, 94 94 part: Selection::All,
+5 -5
macros/src/lib.rs
··· 150 150 .unwrap() 151 151 } 152 152 153 - fn make_year_match(years: &Vec<&str>, inner: &str) -> String { 153 + fn make_year_match(years: &[&str], inner: &str) -> String { 154 154 years 155 155 .iter() 156 - .map(|year| format!("{year} => {},", inner.replace("{year}", &year.to_string()))) 156 + .map(|year| format!("{year} => {},", inner.replace("{year}", year.as_ref()))) 157 157 .collect::<Vec<_>>() 158 158 .join("\n") 159 159 } 160 160 161 - fn make_year_uses(years: &Vec<&str>) -> String { 161 + fn make_year_uses(years: &[&str]) -> String { 162 162 years 163 163 .iter() 164 164 .map(|year| format!("use y_{year}::Year{year};", year = year)) ··· 166 166 .join("\n") 167 167 } 168 168 169 - fn make_run_all_years(years: &Vec<&str>) -> String { 169 + fn make_run_all_years(years: &[&str]) -> String { 170 170 years 171 171 .iter() 172 172 .map(|year| { ··· 179 179 .join("\n") 180 180 } 181 181 182 - fn make_run_year(years: &Vec<&str>) -> String { 182 + fn make_run_year(years: &[&str]) -> String { 183 183 let inner = make_year_match(years, "Year{year}::run_dp(input.as_deref(), dp)"); 184 184 format!( 185 185 "
+11 -14
utils/src/grid.rs
··· 442 442 } 443 443 444 444 /// Like [Grid::relatives] but with `kernels` set to the four cardinal directions. 445 - pub fn adjacent<'a>( 446 - &'a self, 447 - pos: Position, 448 - ) -> impl Iterator<Item = (Direction, Position, &T)> + 'a { 445 + pub fn adjacent(&self, pos: Position) -> impl Iterator<Item = (Direction, Position, &T)> { 449 446 self.relatives(pos, &CARDINALS) 450 447 } 451 448 452 449 /// Like [Grid::relatives_wrapped] but with `kernels` set to the four cardinal directions. 453 - pub fn adjacent_wrapped<'a>( 454 - &'a self, 450 + pub fn adjacent_wrapped( 451 + &self, 455 452 pos: Position, 456 - ) -> impl Iterator<Item = (Direction, Position, &T)> + 'a { 453 + ) -> impl Iterator<Item = (Direction, Position, &T)> { 457 454 self.relatives_wrapped(pos, &CARDINALS) 458 455 } 459 456 460 457 /// Like [Grid::relatives_expand_by] but with `kernels` set to the four cardinal directions. 461 - pub fn adjacent_expand_by<'a>( 462 - &'a self, 458 + pub fn adjacent_expand_by( 459 + &self, 463 460 pos: Position, 464 461 expand: usize, 465 - ) -> impl Iterator<Item = ((Direction, usize), Position, &T)> + 'a { 462 + ) -> impl Iterator<Item = ((Direction, usize), Position, &T)> { 466 463 self.relatives_expand_by(pos, &CARDINALS, expand) 467 464 } 468 465 469 466 /// Like [Grid::relatives_expand_by_wrapped] but with `kernels` set to the four cardinal directions. 470 - pub fn adjacent_expand_by_wrapped<'a>( 471 - &'a self, 467 + pub fn adjacent_expand_by_wrapped( 468 + &self, 472 469 pos: Position, 473 470 expand: usize, 474 - ) -> impl Iterator<Item = ((Direction, usize), Position, &T)> + 'a { 471 + ) -> impl Iterator<Item = ((Direction, usize), Position, &T)> { 475 472 self.relatives_expand_by_wrapped(pos, &CARDINALS, expand) 476 473 } 477 474 } ··· 739 736 } 740 737 741 738 /// Move the cursor forward one step in the direction it is facing and get the value at the new position. 742 - pub fn next(&mut self) -> Option<&T> { 739 + pub fn advance_get(&mut self) -> Option<&T> { 743 740 self.move_forward(); 744 741 self.get() 745 742 }
+19 -22
utils/src/pos.rs
··· 518 518 /// assert_eq!(relatives, vec![(Position::new(0, -1), Direction::North), (Position::new(1, 0), Direction::East)]); 519 519 /// ``` 520 520 /// 521 - pub fn relatives<'a, T: Movement>( 522 - self, 523 - kernels: &'a [T], 524 - ) -> impl Iterator<Item = (Self, T)> + 'a { 525 - kernels.into_iter().map(move |k| (self.move_dir(*k), *k)) 521 + pub fn relatives<T: Movement>(self, kernels: &[T]) -> impl Iterator<Item = (Self, T)> + '_ { 522 + kernels.iter().map(move |k| (self.move_dir(*k), *k)) 526 523 } 527 524 528 525 /// Get all positions relative to this position by a list of directions, ··· 537 534 /// assert_eq!(relatives, vec![(Position::new(1, 0), Direction::East)]); 538 535 /// ``` 539 536 /// 540 - pub fn relatives_checked<'a, T: Movement>( 537 + pub fn relatives_checked<T: Movement>( 541 538 self, 542 - kernels: &'a [T], 539 + kernels: &[T], 543 540 bounds: PositiveType, 544 - ) -> impl Iterator<Item = (Self, T)> + 'a { 541 + ) -> impl Iterator<Item = (Self, T)> + '_ { 545 542 kernels 546 543 .iter() 547 544 .filter_map(move |k| self.move_dir_checked(*k, bounds).map(|p| (p, *k))) ··· 566 563 /// assert_eq!(relatives, expected); 567 564 /// ``` 568 565 /// 569 - pub fn relatives_expand_by<'a, T: Movement>( 566 + pub fn relatives_expand_by<T: Movement>( 570 567 self, 571 - kernels: &'a [T], 568 + kernels: &[T], 572 569 times: usize, 573 - ) -> impl Iterator<Item = ((T, usize), Self)> + 'a { 570 + ) -> impl Iterator<Item = ((T, usize), Self)> + '_ { 574 571 kernels 575 - .into_iter() 572 + .iter() 576 573 .flat_map(move |k| (1..=times).map(move |t| ((*k, t), self.move_times(*k, t)))) 577 574 } 578 575 ··· 594 591 /// assert_eq!(relatives, expected); 595 592 /// ``` 596 593 /// 597 - pub fn relatives_expand_by_checked<'a, T: Movement>( 594 + pub fn relatives_expand_by_checked<T: Movement>( 598 595 self, 599 - kernels: &'a [T], 596 + kernels: &[T], 600 597 times: usize, 601 598 bounds: PositiveType, 602 - ) -> impl Iterator<Item = ((T, usize), Self)> + 'a { 603 - kernels.into_iter().flat_map(move |k| { 599 + ) -> impl Iterator<Item = ((T, usize), Self)> + '_ { 600 + kernels.iter().flat_map(move |k| { 604 601 (1..=times) 605 602 .filter_map(move |t| self.move_times_checked(*k, t, bounds).map(|p| ((*k, t), p))) 606 603 }) ··· 747 744 } 748 745 } 749 746 750 - impl Into<(CompType, CompType)> for Position { 751 - fn into(self) -> (CompType, CompType) { 752 - (self.x, self.y) 747 + impl From<Position> for (CompType, CompType) { 748 + fn from(val: Position) -> Self { 749 + (val.x, val.y) 753 750 } 754 751 } 755 752 ··· 762 759 } 763 760 } 764 761 765 - impl Into<(usize, usize)> for Position { 766 - fn into(self) -> (usize, usize) { 767 - (self.x as usize, self.y as usize) 762 + impl From<Position> for (usize, usize) { 763 + fn from(val: Position) -> Self { 764 + (val.x as usize, val.y as usize) 768 765 } 769 766 } 770 767
+5 -5
utils/src/range.rs
··· 115 115 } 116 116 } 117 117 118 - impl<T: Copy + Clone + Debug + Ord> Into<Range<T>> for BetterRange<T> { 119 - fn into(self) -> Range<T> { 120 - self.start..self.end 118 + impl<T: Copy + Clone + Debug + Ord> From<BetterRange<T>> for Range<T> { 119 + fn from(val: BetterRange<T>) -> Self { 120 + val.start..val.end 121 121 } 122 122 } 123 123 124 124 impl<T: Copy + Clone + Debug + Ord> From<Range<T>> for BetterRange<T> { 125 - fn from(range: Range<T>) -> Self { 126 - Self::new(range.start, range.end) 125 + fn from(val: Range<T>) -> Self { 126 + BetterRange::new(val.start, val.end) 127 127 } 128 128 } 129 129