From b8c259359870b206d2e0bbbd3bfbced91d45146c Mon Sep 17 00:00:00 2001 From: "Jyotirmoy Bandyopadhyaya [Bravo68]" Date: Mon, 25 Dec 2023 14:50:14 +0530 Subject: [PATCH] chore(fmt): lint fixes --- code/rs/src/d15.rs | 1 - code/rs/src/d16.rs | 4 ---- code/rs/src/d21.rs | 2 +- code/rs/src/d22.rs | 15 --------------- code/rs/src/d25.rs | 1 - code/rs/src/d3.rs | 3 --- code/rs/src/d5.rs | 7 ------- code/rs/src/d7.rs | 7 ------- code/ts/23/code.ts | 4 ---- code/ts/24/code.ts | 6 +++--- libs/aoc/index.ts | 2 -- 11 files changed, 4 insertions(+), 48 deletions(-) diff --git a/code/rs/src/d15.rs b/code/rs/src/d15.rs index 3010405..1a6bf95 100644 --- a/code/rs/src/d15.rs +++ b/code/rs/src/d15.rs @@ -58,7 +58,6 @@ fn part2(input: &str) -> usize { acc += (i + 1) * (j + 1) * f.1 as usize; } } - // return as integer acc } diff --git a/code/rs/src/d16.rs b/code/rs/src/d16.rs index a7f7805..824ca58 100644 --- a/code/rs/src/d16.rs +++ b/code/rs/src/d16.rs @@ -76,17 +76,14 @@ pub fn part1(data: &str) -> Option { } pub fn part2(data: &str) -> Option { - // Split the input string into lines and collect into a vector let grid = data.lines().collect::>(); - // Generate starting points for traversal in all four directions let right_starts = (0..grid.len()).map(|y| (y, 0, Direction::R)); let down_starts = (0..grid.first()?.len()).map(|x| (0, x, Direction::D)); let left_starts = (0..grid.len()).filter_map(|y| Some((y, grid[y].len().checked_sub(1)?, Direction::L))); let up_starts = (0..grid.last()?.len()).map(|x| (grid.len() - 1, x, Direction::U)); - // Combine all starting points and process in parallel let result = right_starts .chain(down_starts) .chain(left_starts) @@ -95,7 +92,6 @@ pub fn part2(data: &str) -> Option { .filter_map(|(y, x, direction)| fill(&grid, y, x, direction)) .max(); - // Return the result result } diff --git a/code/rs/src/d21.rs b/code/rs/src/d21.rs index fa2eada..1f0102e 100644 --- a/code/rs/src/d21.rs +++ b/code/rs/src/d21.rs @@ -51,7 +51,7 @@ fn generate_neighbors(position: (isize, isize)) -> Vec<(isize, isize)> { } fn solve_steps(garden: Garden, num_steps: isize) -> usize { - let mut queue = vec![((0, 0), 0)]; // position, number of steps so far + let mut queue = vec![((0, 0), 0)]; let mut visited = HashSet::new(); while let Some(state) = queue.pop() { diff --git a/code/rs/src/d22.rs b/code/rs/src/d22.rs index 8ec6f1a..61d4f10 100644 --- a/code/rs/src/d22.rs +++ b/code/rs/src/d22.rs @@ -91,11 +91,9 @@ impl Brick { fn move_down(&mut self) { self.min.z -= 1; self.max.z -= 1; - // this is probably inefficient? self.cubes = Self::cubes(self.min, self.max); } - // generate all the cubes for this brick fn cubes(min: Triple, max: Triple) -> BTreeSet { (min.z..=max.z) .flat_map(|z| { @@ -129,25 +127,19 @@ impl Ord for Brick { } fn settle(input: &[Brick]) -> Input { - // sort the bricks by z index let mut bricks = input.to_vec(); bricks.sort(); - // The 3D tower, with brick id being the value let mut settled: BTreeMap = BTreeMap::new(); - // the "graph" indicating which bricks support other bricks let mut holding_up: SupportMap = BTreeMap::new(); let mut sitting_on: SupportMap = BTreeMap::new(); for brick in bricks.iter_mut() { - // set up our graph from here holding_up.insert(brick.id, BTreeSet::new()); sitting_on.insert(brick.id, BTreeSet::new()); - // move down until we find something below us let bricks_below = loop { - // if we hit the ground, return nothing if brick.on_ground() { break vec![]; } @@ -159,7 +151,6 @@ fn settle(input: &[Brick]) -> Input { .cloned() .collect(); - // if there are bricks below us, return their IDs if !bricks_below.is_empty() { break bricks_below; } @@ -167,10 +158,8 @@ fn settle(input: &[Brick]) -> Input { brick.move_down(); }; - // now that we dropped all the way, set the id where we landed settled.extend(brick.cubes.iter().map(|c| (*c, brick.id))); - // set up the graph for each of the bricks for below in bricks_below { holding_up.entry(below).or_default().insert(brick.id); sitting_on.entry(brick.id).or_default().insert(below); @@ -194,14 +183,11 @@ fn part2(input: &Input) -> usize { holding_up .iter() .map(|(brick, above)| { - // start considering everything above us let mut queue: VecDeque = VecDeque::from_iter(above.iter().cloned()); let mut unsupported: BTreeSet = BTreeSet::from_iter(vec![*brick]); while let Some(brick) = queue.pop_front() { - // if all of the bricks that we're sitting on are unsupported if sitting_on[&brick].is_subset(&unsupported) { - // this one is unsupported, and consider the rest of the ones sitting on us unsupported.insert(brick); for b in &holding_up[&brick] { queue.push_back(*b); @@ -209,7 +195,6 @@ fn part2(input: &Input) -> usize { } } - // discount the original brick we put in the falling set to get the rest of it to work unsupported.len() - 1 }) .sum() diff --git a/code/rs/src/d25.rs b/code/rs/src/d25.rs index 45034b8..e8897b4 100644 --- a/code/rs/src/d25.rs +++ b/code/rs/src/d25.rs @@ -79,7 +79,6 @@ fn part1(input: &str) -> usize { let graph = parse_graph(input); let vertices: Vec<&str> = graph.keys().map(|x| *x).collect(); let mut set1: Vec<&str> = Vec::new(); - // Add vertex 0 to the set set1.push(vertices[0]); let mut j = 0; while j < set1.len() { diff --git a/code/rs/src/d3.rs b/code/rs/src/d3.rs index 916bafb..027509a 100644 --- a/code/rs/src/d3.rs +++ b/code/rs/src/d3.rs @@ -18,13 +18,11 @@ fn build_part_map(map: &Matrix) -> BTreeMap<(usize, usize), Vec> { .take_while(|(_, c)| c.is_ascii_digit()) .collect::>(); - // Check if is part number if let Some(gear) = number .iter() .flat_map(|(j, _)| map.neighbours((i, *j), true)) .find(|(i, j)| map[(*i, *j)] != '.' && !map[(*i, *j)].is_numeric()) { - // Parse number let n = number .into_iter() .map(|(_, c)| c) @@ -32,7 +30,6 @@ fn build_part_map(map: &Matrix) -> BTreeMap<(usize, usize), Vec> { .parse::() .unwrap(); - // Add to part numbers part_numbers.entry(gear).or_default().push(n); } } diff --git a/code/rs/src/d5.rs b/code/rs/src/d5.rs index 50e2a3b..19b7821 100644 --- a/code/rs/src/d5.rs +++ b/code/rs/src/d5.rs @@ -20,23 +20,18 @@ fn map_seeds_ranges(seeds: Vec>, mappings: &Mappings) -> Vec seed_range.start && *source_range_start < seed_range.end }) - // Sort them to only have to apply them once and avoid collisions .sorted_by_key(|(_, source_range_start, _)| *source_range_start) .fold( seed_range.start, |current, (destination_range_start, source_range_start, range_length)| { - // From current to start of the mapping if current < *source_range_start { mapped_ranges.push(current..*source_range_start); } - // From start of the mapping or start of the seed range - // To end of the mapping or end of the seed range let common_start = current.max(*source_range_start); let common_end = seed_range.end.min(source_range_start + range_length); mapped_ranges.push( @@ -44,12 +39,10 @@ fn map_seeds_ranges(seeds: Vec>, mappings: &Mappings) -> Vec>() .as_slice() { - // Five of a kind [(5, _)] | [(4, Card::Joker), (1, _)] | [(4, _), (1, Card::Joker)] | [(3, _), (2, Card::Joker)] | [(3, Card::Joker), (2, _)] => Self::FiveOfAKind, - // Four of a kind [(4, _), (1, _)] | [(3, Card::Joker), (1, _), (1, _)] | [(3, _), (1, Card::Joker), (1, _)] @@ -74,10 +72,8 @@ impl HandType { | [(2, Card::Joker), (2, _), (1, _)] | [(2, _), (2, Card::Joker), (1, _)] => Self::FourOfAKind, - // Full house [(3, _), (2, _)] | [(2, _), (2, _), (_, Card::Joker)] => Self::FullHouse, - // Three of a kind [(3, _), (_, _), (_, _)] | [(2, Card::Joker), (1, _), (1, _), (1, _)] => { Self::ThreeOfAKind } @@ -85,14 +81,11 @@ impl HandType { Self::ThreeOfAKind } - // Two pair [(2, _), (2, _), (_, _)] => Self::TwoPair, - // One pair [(2, _), (_, _), (_, _), (_, _)] => Self::OnePair, cc if cc.contains(&(&1, &&Card::Joker)) => Self::OnePair, - // High card [(1, _), (_, _), (_, _), (_, _), (_, _)] => Self::HighCard, hand => panic!("Invalid hand {hand:?}"), diff --git a/code/ts/23/code.ts b/code/ts/23/code.ts index e7fec1d..d977709 100644 --- a/code/ts/23/code.ts +++ b/code/ts/23/code.ts @@ -71,7 +71,6 @@ const crossings = {} as Record< } >; -// Find all crossroads const dots = matrixFindElements(matrix, { value: "." }); for (const [pos] of dots) { const neigs = xydirections(pos) @@ -85,7 +84,6 @@ crossings[xykey(target)] = { pos: target, paths: {} }; const m2 = matrixClone(matrix); Object.values(crossings).forEach(({ pos }) => matrixSet(m2, pos, "X")); -// Find path lengths between crossroads for (const crossing of Object.values(crossings)) { const xpos = crossing.pos; const neigs = xydirections(xpos); @@ -105,7 +103,6 @@ for (const crossing of Object.values(crossings)) { } } -// Find longest path through crossroads const itFinder2 = findPathsFlexi<[string, string[]]>({ startNodes: [[xykey(start), [xykey(start)]]], endCondition: ([key]) => key == xykey(target), @@ -115,7 +112,6 @@ const itFinder2 = findPathsFlexi<[string, string[]]>({ .map(v => [v, [...path, v]]), costFn: ([to], cost, [from]) => cost + crossings[from].paths[to], prioritizeHighCost: true, - // Importantly, no cacheKeyFn passed in }); let max2 = 0; diff --git a/code/ts/24/code.ts b/code/ts/24/code.ts index a655723..385efd9 100644 --- a/code/ts/24/code.ts +++ b/code/ts/24/code.ts @@ -74,7 +74,7 @@ export const part1 = (input: string): string | number => { const startY = py + vy * startTime; const endY = py + vy * endTime; if (startTime > endTime) { - return false; // X and Y don't fall in zone at the same time + return false; } return { start: xy(startX, startY), @@ -88,7 +88,7 @@ export const part1 = (input: string): string | number => { const [[aPX, aPY], [aVX, aVY]] = hailstones[i]; const aBounds = hailstoneBounds[i] || getBounds(aPX, aPY, aVX, aVY); hailstoneBounds[i] = aBounds; - if (!aBounds) continue; // Not in zone + if (!aBounds) continue; for (let j = 1; j < hailstones.length; j++) { if (i === j) continue; const pairKey = (i < j ? [i, j] : [j, i]).join(":"); @@ -97,7 +97,7 @@ export const part1 = (input: string): string | number => { const [[bPX, bPY], [bVX, bVY]] = hailstones[j]; const bBounds = hailstoneBounds[j] || getBounds(bPX, bPY, bVX, bVY); hailstoneBounds[j] = bBounds; - if (!bBounds) continue; // Not in zone + if (!bBounds) continue; if (getSegmentIntersection(aBounds.start, aBounds.end, bBounds.start, bBounds.end)) { intersections++; } diff --git a/libs/aoc/index.ts b/libs/aoc/index.ts index 02ae70c..608175d 100644 --- a/libs/aoc/index.ts +++ b/libs/aoc/index.ts @@ -2,10 +2,8 @@ const today = new Date(); const day = today.getDate(); -// Download input Bun.spawn(["aoc", "-I", "-i", `../../input/${day}.txt`, "-d", day.toString(), "download"]); -// Create new project const proc = Bun.spawn(["bash", "../../scripts/init.sh"]); const output = await new Response(proc.stdout).text();