mirror of
https://github.com/rjNemo/ai_advent_code_2024
synced 2026-06-06 02:26:44 +00:00
test: add test for day4
This commit is contained in:
parent
a4d9ba205a
commit
13d056a471
3 changed files with 94 additions and 1 deletions
|
|
@ -1 +0,0 @@
|
|||
# Add your puzzle input here
|
||||
71
lib/advent_code2024/solutions/day04/READme.md
Normal file
71
lib/advent_code2024/solutions/day04/READme.md
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
# Coding Challenge: Ceres Search
|
||||
|
||||
## Problem Summary
|
||||
|
||||
You are presented with a word search puzzle where you must find all occurrences of
|
||||
the word "XMAS". The word can appear in various directions and orientations, including:
|
||||
|
||||
- Horizontal (left-to-right and right-to-left)
|
||||
- Vertical (top-to-bottom and bottom-to-top)
|
||||
- Diagonal (both directions)
|
||||
- Overlapping with other words
|
||||
|
||||
## Example Puzzle
|
||||
|
||||
Below is a simplified word search grid where irrelevant characters are replaced
|
||||
with `.`:
|
||||
|
||||
```txt
|
||||
..X...
|
||||
.SAMX.
|
||||
.A..A.
|
||||
XMAS.S
|
||||
.X....
|
||||
```
|
||||
|
||||
In this grid, "XMAS" can appear in multiple ways.
|
||||
|
||||
## Larger Example
|
||||
|
||||
For the following complete grid:
|
||||
|
||||
```txt
|
||||
MMMSXXMASM
|
||||
MSAMXMSMSA
|
||||
AMXSXMAAMM
|
||||
MSAMASMSMX
|
||||
XMASAMXAMM
|
||||
XXAMMXXAMA
|
||||
SMSMSASXSS
|
||||
SAXAMASAAA
|
||||
MAMMMXMMMM
|
||||
MXMXAXMASX
|
||||
```
|
||||
|
||||
The word "XMAS" occurs **18 times**. Visualizing the grid with only the letters
|
||||
in "XMAS" highlighted:
|
||||
|
||||
```txt
|
||||
....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
|
||||
```
|
||||
|
||||
## Objective
|
||||
|
||||
For the given puzzle input, calculate and return the total number of times the word
|
||||
"XMAS" appears in all possible orientations.
|
||||
|
||||
## Notes
|
||||
|
||||
- Words can overlap and share characters.
|
||||
- Input will be a rectangular grid of letters.
|
||||
|
||||
Good luck helping the little Elf! 🌟
|
||||
23
test/advent_code2024/solutions/day04/day4_test.exs
Normal file
23
test/advent_code2024/solutions/day04/day4_test.exs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
defmodule AdventCode2024.Solutions.Day04Test do
|
||||
use ExUnit.Case
|
||||
alias AdventCode2024.Solutions.Day04
|
||||
|
||||
@example_grid [
|
||||
"MMMSXXMASM",
|
||||
"MSAMXMSMSA",
|
||||
"AMXSXMAAMM",
|
||||
"MSAMASMSMX",
|
||||
"XMASAMXAMM",
|
||||
"XXAMMXXAMA",
|
||||
"SMSMSASXSS",
|
||||
"SAXAMASAAA",
|
||||
"MAMMMXMMMM",
|
||||
"MXMXAXMASX"
|
||||
]
|
||||
|
||||
test "count occurrences of XMAS in word search" do
|
||||
expected_count = 18
|
||||
actual_count = Day04.count_word_occurrences(@example_grid, "XMAS")
|
||||
assert actual_count == expected_count
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue