From 8b698738c521b36e71427bb094fb596eed19622b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Borna=20Rajkovi=C4=87?= Date: Wed, 4 Dec 2024 18:26:41 +0100 Subject: [PATCH] Day 04. solutions --- data.go | 3 + day_04/complex_example_data.txt | 10 +++ day_04/data.txt | 140 ++++++++++++++++++++++++++++++++ day_04/example_data.txt | 10 +++ day_04/solution.go | 130 +++++++++++++++++++++++++++++ day_04/solution_test.go | 27 ++++++ main.go | 5 ++ 7 files changed, 325 insertions(+) create mode 100644 day_04/complex_example_data.txt create mode 100644 day_04/data.txt create mode 100644 day_04/example_data.txt create mode 100644 day_04/solution.go create mode 100644 day_04/solution_test.go diff --git a/data.go b/data.go index 941c7e6..93ce276 100644 --- a/data.go +++ b/data.go @@ -12,3 +12,6 @@ var Day02Data string //go:embed day_03/data.txt var Day03Data string + +//go:embed day_04/data.txt +var Day04Data string diff --git a/day_04/complex_example_data.txt b/day_04/complex_example_data.txt new file mode 100644 index 0000000..c41c5ea --- /dev/null +++ b/day_04/complex_example_data.txt @@ -0,0 +1,10 @@ +MMMSXXMASM +MSAMXMSMSA +AMXSXMAAMM +MSAMASMSMX +XMASAMXAMM +XXAMMXXAMA +SMSMSASXSS +SAXAMASAAA +MAMMMXMMMM +MXMXAXMASX \ No newline at end of file diff --git a/day_04/data.txt b/day_04/data.txt new file mode 100644 index 0000000..97c11e0 --- /dev/null +++ b/day_04/data.txt @@ -0,0 +1,140 @@ +XMASAXMASXXMMAMAXAXXXMSASXSXSXMAMMAMXMASASXMXMASMSMSSMMSXMASXMSMXMASMMSSMMMSMMAMMSMMMMMSXMAXMSMMMMMSAXAXXXMASAMXXSXMXSSSMSMSXMAMXXXSAXSMSAMX +MSMMMMSMXMXSSSSSSMSMSMSASAAXXASAXXMAXSMSAMMSAMSXAAAAXSAMXMASXMXMASAMXXAAAXMAMMAAMAMXAASAMMMSAMXMAASMSXMSMSMXMASMXMASXMAAXAAAXXSSSMMAMMXAXSXX +AAAAAAAM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SMSAMXXXXMAMXMXMSAMXSSSMSAMXAMXSSMMASAXXAXMMSXSMSAMXAXMSMXSMSMXSSSMSMSASAMXXSXSXSAMXSAMXMAS \ No newline at end of file diff --git a/day_04/example_data.txt b/day_04/example_data.txt new file mode 100644 index 0000000..c41c5ea --- /dev/null +++ b/day_04/example_data.txt @@ -0,0 +1,10 @@ +MMMSXXMASM +MSAMXMSMSA +AMXSXMAAMM +MSAMASMSMX +XMASAMXAMM +XXAMMXXAMA +SMSMSASXSS +SAXAMASAAA +MAMMMXMMMM +MXMXAXMASX \ No newline at end of file diff --git a/day_04/solution.go b/day_04/solution.go new file mode 100644 index 0000000..5cb3949 --- /dev/null +++ b/day_04/solution.go @@ -0,0 +1,130 @@ +package day_04 + +import "strings" + +// task:https://adventofcode.com/2024/day/2 +// short summary - count all instances of XMAS in the 2d array +func SolveBasic(input string) int { + grid := toGrid(input) + found := 0 + for y := 0; y < len(grid); y++ { + for x := 0; x < len(grid[y]); x++ { + if grid[y][x] == 'X' { + found += checkForXMAS(grid, x, y) + } + } + } + return found +} + +// task:https://adventofcode.com/2024/day/2#part2 +// short summary - +func SolveComplex(input string) int { + grid := toGrid(input) + found := 0 + for y := 1; y < len(grid)-1; y++ { + for x := 1; x < len(grid[y])-1; x++ { + if grid[y][x] == 'A' { + if checkForX_MAS(grid, x, y) { + found++ + } + } + } + } + return found +} + +// helper methods +func toGrid(input string) [][]rune { + substrings := strings.Split(input, "\n") + var grid [][]rune + for _, line := range substrings { + grid = append(grid, []rune(line)) + } + return grid +} + +func checkForXMAS(grid [][]rune, x int, y int) int { + found := 0 + // going clockwise from top left + if x >= 3 && y >= 3 { + if checkLineForXMAS(grid, x, y, -1, -1) { + found++ + } + } + if y >= 3 { + if checkLineForXMAS(grid, x, y, 0, -1) { + found++ + } + } + if y >= 3 && x < len(grid[y])-3 { + if checkLineForXMAS(grid, x, y, 1, -1) { + found++ + } + } + if x < len(grid[y])-3 { + if checkLineForXMAS(grid, x, y, 1, 0) { + found++ + } + } + if y < len(grid)-3 && x < len(grid[y])-3 { + if checkLineForXMAS(grid, x, y, 1, 1) { + found++ + } + } + if y < len(grid)-3 { + if checkLineForXMAS(grid, x, y, 0, 1) { + found++ + } + } + if x >= 3 && y < len(grid)-3 { + if checkLineForXMAS(grid, x, y, -1, 1) { + found++ + } + } + if x >= 3 { + if checkLineForXMAS(grid, x, y, -1, 0) { + found++ + } + } + return found +} + +func checkForX_MAS(grid [][]rune, x int, y int) bool { + // M.M + // .A. + // S.S + if grid[y-1][x-1] == 'M' && grid[y-1][x+1] == 'M' && + grid[y+1][x-1] == 'S' && grid[y+1][x+1] == 'S' { + return true + } + // S.M + // .A. + // S.M + if grid[y-1][x-1] == 'S' && grid[y-1][x+1] == 'M' && + grid[y+1][x-1] == 'S' && grid[y+1][x+1] == 'M' { + return true + } + // M.S + // .A. + // M.S + if grid[y-1][x-1] == 'M' && grid[y-1][x+1] == 'S' && + grid[y+1][x-1] == 'M' && grid[y+1][x+1] == 'S' { + return true + } + // S.S + // .A. + // M.M + if grid[y-1][x-1] == 'S' && grid[y-1][x+1] == 'S' && + grid[y+1][x-1] == 'M' && grid[y+1][x+1] == 'M' { + return true + } + + return false +} + +func checkLineForXMAS(grid [][]rune, x int, y int, xStep int, yStep int) bool { + return grid[y+yStep][x+xStep] == 'M' && + grid[y+2*yStep][x+2*xStep] == 'A' && + grid[y+3*yStep][x+3*xStep] == 'S' +} diff --git a/day_04/solution_test.go b/day_04/solution_test.go new file mode 100644 index 0000000..b5e1dfc --- /dev/null +++ b/day_04/solution_test.go @@ -0,0 +1,27 @@ +package day_04_test + +import ( + "advent_of_code_2024/day_04" + _ "embed" + "testing" +) + +//go:embed example_data.txt +var ExampleData string + +//go:embed complex_example_data.txt +var ComplexExampleData string + +func TestBasicSolutionExample(t *testing.T) { + result := day_04.SolveBasic(ExampleData) + if result != 18 { + t.Fatalf("Expected 18 received %d", result) + } +} + +func TestComplexSolutionExample(t *testing.T) { + result := day_04.SolveComplex(ComplexExampleData) + if result != 9 { + t.Fatalf("Expected 9 received %d", result) + } +} diff --git a/main.go b/main.go index dd88090..4520c79 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "advent_of_code_2024/day_01" "advent_of_code_2024/day_02" "advent_of_code_2024/day_03" + "advent_of_code_2024/day_04" _ "embed" "fmt" "os" @@ -25,6 +26,10 @@ func main() { fmt.Printf("Day 03. Basic: %d\n", day_03.SolveBasic(Day03Data)) // 189527826 case "03-complex": fmt.Printf("Day 03. Complex: %d\n", day_03.SolveComplex(Day03Data)) // 63013756 + case "04-basic": + fmt.Printf("Day 04. Basic: %d\n", day_04.SolveBasic(Day04Data)) // 2560 + case "04-complex": + fmt.Printf("Day 04. Complex: %d\n", day_04.SolveComplex(Day04Data)) // 63013756 } }