From 4f5ae71599889c6a01144ea25fa291608159f4bc Mon Sep 17 00:00:00 2001 From: Ruidy Date: Wed, 4 Dec 2024 13:36:42 +0100 Subject: [PATCH] remove the implementation --- lib/advent_code2024/solutions/day04/day4.ex | 72 --------------------- 1 file changed, 72 deletions(-) diff --git a/lib/advent_code2024/solutions/day04/day4.ex b/lib/advent_code2024/solutions/day04/day4.ex index deece46..289f9cd 100644 --- a/lib/advent_code2024/solutions/day04/day4.ex +++ b/lib/advent_code2024/solutions/day04/day4.ex @@ -86,77 +86,5 @@ defmodule AdventCode2024.Solutions.Day04 do end def count_x_mas(grid) do - directions = [ - # Down - {1, 0}, - # Right - {0, 1}, - # Down-right diagonal - {1, 1}, - # Down-left diagonal - {1, -1} - ] - - grid_chars = Enum.map(grid, &String.graphemes/1) - - grid_chars - |> Enum.with_index() - |> Enum.reduce(0, fn {row, row_idx}, acc -> - row - |> Enum.with_index() - |> Enum.reduce(acc, fn {_, col_idx}, acc_inner -> - acc_inner + count_xmas_from(grid_chars, {row_idx, col_idx}, directions) - end) - end) - end - - defp count_xmas_from(grid, {row, col}, directions) do - directions - |> Enum.reduce(0, fn direction, acc -> - if find_xmas?(grid, {row, col}, direction) do - acc + 1 - else - acc - end - end) - end - - defp find_xmas?(grid, {row, col}, {d_row, d_col}) do - # Define the positions for the X pattern - positions_right = [ - # M - {row, col}, - # A - {row + d_row, col + d_col}, - # S - {row + 2 * d_row, col + 2 * d_col} - ] - - positions_left = [ - # M - {row, col + 2 * d_col}, - # A (center shared) - {row + d_row, col + d_col}, - # S - {row + 2 * d_row, col} - ] - - # Check both diagonals for "MAS" (can be forwards or backwards) - (check_mas?(grid, positions_right) or check_sam?(grid, positions_right)) and - (check_mas?(grid, positions_left) or check_sam?(grid, positions_left)) - end - - defp check_mas?(grid, [{r1, c1}, {r2, c2}, {r3, c3}]) do - within_bounds?(grid, r1, c1) and within_bounds?(grid, r2, c2) and within_bounds?(grid, r3, c3) and - Enum.at(Enum.at(grid, r1), c1) == "M" and - Enum.at(Enum.at(grid, r2), c2) == "A" and - Enum.at(Enum.at(grid, r3), c3) == "S" - end - - defp check_sam?(grid, [{r1, c1}, {r2, c2}, {r3, c3}]) do - within_bounds?(grid, r1, c1) and within_bounds?(grid, r2, c2) and within_bounds?(grid, r3, c3) and - Enum.at(Enum.at(grid, r1), c1) == "S" and - Enum.at(Enum.at(grid, r2), c2) == "A" and - Enum.at(Enum.at(grid, r3), c3) == "M" end end