diff --git a/advent-of-code/2024/day_04/.formatter.exs b/advent-of-code/2024/day_04/.formatter.exs new file mode 100644 index 0000000..d2cda26 --- /dev/null +++ b/advent-of-code/2024/day_04/.formatter.exs @@ -0,0 +1,4 @@ +# Used by "mix format" +[ + inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"] +] diff --git a/advent-of-code/2024/day_04/.gitignore b/advent-of-code/2024/day_04/.gitignore new file mode 100644 index 0000000..e002254 --- /dev/null +++ b/advent-of-code/2024/day_04/.gitignore @@ -0,0 +1,26 @@ +# The directory Mix will write compiled artifacts to. +/_build/ + +# If you run "mix test --cover", coverage assets end up here. +/cover/ + +# The directory Mix downloads your dependencies sources to. +/deps/ + +# Where third-party dependencies like ExDoc output generated docs. +/doc/ + +# Ignore .fetch files in case you like to edit your project deps locally. +/.fetch + +# If the VM crashes, it generates a dump, let's ignore it too. +erl_crash.dump + +# Also ignore archive artifacts (built via "mix archive.build"). +*.ez + +# Ignore package tarball (built via "mix hex.build"). +day_04-*.tar + +# Temporary files, for example, from tests. +/tmp/ diff --git a/advent-of-code/2024/day_04/README.md b/advent-of-code/2024/day_04/README.md new file mode 100644 index 0000000..2f94f66 --- /dev/null +++ b/advent-of-code/2024/day_04/README.md @@ -0,0 +1,87 @@ +# Day 4: Ceres Search + +"Looks like the Chief's not here. Next!" One of The Historians pulls out a device and pushes the only button on it. +After a brief flash, you recognize the interior of the Ceres monitoring station! + +As the search for the Chief continues, a small Elf who lives on the station tugs on your shirt; +she'd like to know if you could help her with her word search (your puzzle input). She only has to find one word: XMAS. + +This word search allows words to be horizontal, vertical, diagonal, written backwards, or even overlapping other words. +It's a little unusual, though, as you don't merely need to find one instance of XMAS - you need to find all of them. +Here are a few ways XMAS might appear, where irrelevant characters have been replaced with `.`: + +``` +..X... +.SAMX. +.A..A. +XMAS.S +.X.... +``` + +The actual word search will be full of letters instead. For example: + +``` +MMMSXXMASM +MSAMXMSMSA +AMXSXMAAMM +MSAMASMSMX +XMASAMXAMM +XXAMMXXAMA +SMSMSASXSS +SAXAMASAAA +MAMMMXMMMM +MXMXAXMASX +``` + +In this word search, XMAS occurs a total of 18 times; here's the same word search again, +but where letters not involved in any XMAS have been replaced with `.`: + +``` +....XXMAS. +.SAMXMS... +...S..A... +..A.A.MS.X +XMASAMX.MM +X.....XA.A +S.S.S.S.SS +.A.A.A.A.A +..M.M.M.MM +.X.X.XMASX +``` + +Take a look at the little Elf's word search. How many times does XMAS appear? + + +## Part Two + +The Elf looks quizzically at you. Did you misunderstand the assignment? + +Looking for the instructions, you flip over the word search to find that this isn't actually an XMAS puzzle; +it's an X-MAS puzzle in which you're supposed to find two MAS in the shape of an X. One way to achieve that is like this: + +``` +M.S +.A. +M.S +``` + +Irrelevant characters have again been replaced with `.` in the above diagram. Within the X, each MAS can be written forwards or backwards. + +Here's the same example from before, but this time all of the X-MASes have been kept instead: + +``` +.M.S...... +..A..MSMS. +.M.S.MAA.. +..A.ASMSM. +.M.S.M.... +.......... +S.S.S.S.S. +.A.A.A.A.. +M.M.M.M.M. +.......... +``` + +In this example, an X-MAS appears 9 times. + +Flip the word search from the instructions back over to the word search side and try again. How many times does an X-MAS appear? diff --git a/advent-of-code/2024/day_04/input.txt b/advent-of-code/2024/day_04/input.txt new file mode 100644 index 0000000..5f2c4dc --- /dev/null +++ b/advent-of-code/2024/day_04/input.txt @@ -0,0 +1,140 @@ +SAMMSMSXMMXXXXSSSMXMAXAMSSSSMSAXMXSSXXXSMMSMMXMASXSSSSSMSMMXMAXMSMMMASMSXSAMMXMMMSMXXSMMXSMXSXXXXMMMMXMASMMMSAMXXSSMMSMAMXMSSMXSSMMSAMSAMXMM +MASAAAMAMMAMSMMAAXMSSXMSAMAAXXMAMAMXMSMMMXSASXSMSMMAAAXMAMSAMXSMAASMXXASMSASMMSAMASXXMAMAMMAMXMMMMAASAMXAXASXSXSASAAAAXAXXMAAASXSXAMAXAMSASX +SAMXSMSMMMAMMAMSMMXAMAXMAMMMMSSSMXSAAAA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SXXMASMXMXMASMMMSSSMMMSSMSAMXMXSMMMXMSSSMSSSMAMM diff --git a/advent-of-code/2024/day_04/lib/day04.ex b/advent-of-code/2024/day_04/lib/day04.ex new file mode 100644 index 0000000..cc34a7b --- /dev/null +++ b/advent-of-code/2024/day_04/lib/day04.ex @@ -0,0 +1,16 @@ +defmodule Mix.Tasks.Solve do + use Mix.Task + + @impl Mix.Task + def run(_) do + input = + File.stream!("input.txt") + |> Enum.map(&String.trim/1) + + res = Xmas.count_xmas(input) + IO.puts("Part 1: #{res}") + + res = Mas.count_mas(input) + IO.puts("Part 2: #{res}") + end +end diff --git a/advent-of-code/2024/day_04/lib/mas.ex b/advent-of-code/2024/day_04/lib/mas.ex new file mode 100644 index 0000000..1c4bded --- /dev/null +++ b/advent-of-code/2024/day_04/lib/mas.ex @@ -0,0 +1,28 @@ +defmodule Mas do + def count_mas(input) do + input + |> Enum.map(&String.graphemes/1) + |> extract_fragments() + end + + def extract_fragments(matrix) do + matrix + |> Enum.map(fn row -> Enum.chunk_every(row, 3, 1, :discard) end) + |> Enum.zip_reduce([], fn elements, acc -> [elements | acc] end) + |> Enum.map(fn col -> Enum.chunk_every(col, 3, 1, :discard) end) + |> Enum.map(fn x -> Enum.map(x, &is_mas/1) end) + |> List.flatten() + |> Enum.reduce(0, fn x, acc -> if x, do: acc + 1, else: acc end) + end + + def is_mas(triplet) do + str = + triplet + |> List.flatten() + |> Enum.join() + + [~r/M.S.A.M.S/, ~r/M.M.A.S.S/, ~r/S.M.A.S.M/, ~r/S.S.A.M.M/] + |> Enum.map(fn regex -> String.match?(str, regex) end) + |> Enum.reduce(false, fn x, acc -> acc or x end) + end +end diff --git a/advent-of-code/2024/day_04/lib/xmas.ex b/advent-of-code/2024/day_04/lib/xmas.ex new file mode 100644 index 0000000..a938132 --- /dev/null +++ b/advent-of-code/2024/day_04/lib/xmas.ex @@ -0,0 +1,84 @@ +defmodule Xmas do + def count_xmas(input) do + horizontal = + input + |> Enum.map(&count_xmas_in_str/1) + |> Enum.sum() + + vertical = + input + |> transpose() + |> Enum.map(&count_xmas_in_str/1) + |> Enum.sum() + + diagonal = + input + |> get_diagonals() + |> Enum.map(&count_xmas_in_str/1) + |> Enum.sum() + + diagonal_inverted = + input + |> Enum.map(&String.reverse/1) + |> get_diagonals() + |> Enum.map(&count_xmas_in_str/1) + |> Enum.sum() + + horizontal + vertical + diagonal + diagonal_inverted + end + + def transpose(input) do + input + |> Enum.map(&String.graphemes/1) + |> Enum.zip_with(&Function.identity/1) + |> Enum.map(&Enum.join/1) + end + + def get_diagonals(input) do + matrix = + input + |> Enum.map(&String.graphemes/1) + + {width, height} = get_dimensions(matrix) + + Enum.map(1..(width + height - 1), fn n -> get_nth_diagonal(matrix, n) end) + end + + def get_nth_diagonal(matrix, n) do + {width, height} = get_dimensions(matrix) + + first_row = max(0, n - width) + last_row = min(height, first_row + n - 1) + max_char_idx = min(width, n) - 1 + + matrix + |> Enum.slice(first_row..last_row) + |> Enum.with_index(fn row, idx -> Enum.at(row, max_char_idx - idx) end) + |> Enum.join() + end + + def get_dimensions(matrix) do + width = + matrix + |> hd() + |> Enum.count() + + height = Enum.count(matrix) + + {width, height} + end + + def count_xmas_in_str(input, acc \\ 0) + + def count_xmas_in_str("", acc) do + acc + end + + def count_xmas_in_str(input, acc) do + acc = if String.starts_with?(input, "XMAS"), do: acc + 1, else: acc + acc = if String.starts_with?(input, "SAMX"), do: acc + 1, else: acc + new_input = String.slice(input, 1..-1//1) + + count_xmas_in_str(new_input, acc) + end +end diff --git a/advent-of-code/2024/day_04/mix.exs b/advent-of-code/2024/day_04/mix.exs new file mode 100644 index 0000000..368989a --- /dev/null +++ b/advent-of-code/2024/day_04/mix.exs @@ -0,0 +1,28 @@ +defmodule Day04.MixProject do + use Mix.Project + + def project do + [ + app: :day_04, + version: "0.1.0", + elixir: "~> 1.16", + start_permanent: Mix.env() == :prod, + deps: deps() + ] + end + + # Run "mix help compile.app" to learn about applications. + def application do + [ + extra_applications: [:logger] + ] + end + + # Run "mix help deps" to learn about dependencies. + defp deps do + [ + # {:dep_from_hexpm, "~> 0.3.0"}, + # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} + ] + end +end diff --git a/advent-of-code/2024/day_04/test/test_helper.exs b/advent-of-code/2024/day_04/test/test_helper.exs new file mode 100644 index 0000000..869559e --- /dev/null +++ b/advent-of-code/2024/day_04/test/test_helper.exs @@ -0,0 +1 @@ +ExUnit.start() diff --git a/advent-of-code/2024/day_04/test/xmas_test.exs b/advent-of-code/2024/day_04/test/xmas_test.exs new file mode 100644 index 0000000..125b133 --- /dev/null +++ b/advent-of-code/2024/day_04/test/xmas_test.exs @@ -0,0 +1,31 @@ +defmodule XmasTest do + use ExUnit.Case + doctest Xmas + + test "count xmas" do + assert Xmas.count_xmas_in_str("ABXMASAMXABXMASABSAMX") == 4 + end + + test "diagonals" do + input = ["abc", "def", "ghi", "jkl"] + diagonals = ["a", "bd", "ceg", "fhj", "ik", "l"] + assert Xmas.get_diagonals(input) == diagonals + end + + test "example 1" do + input = [ + "MMMSXXMASM", + "MSAMXMSMSA", + "AMXSXMAAMM", + "MSAMASMSMX", + "XMASAMXAMM", + "XXAMMXXAMA", + "SMSMSASXSS", + "SAXAMASAAA", + "MAMMMXMMMM", + "MXMXAXMASX" + ] + + assert Xmas.count_xmas(input) == 18 + end +end