Day 04. solutions

This commit is contained in:
Borna Rajković 2024-12-04 18:26:41 +01:00
parent c0380e9aea
commit 8b698738c5
7 changed files with 325 additions and 0 deletions

View File

@ -12,3 +12,6 @@ var Day02Data string
//go:embed day_03/data.txt //go:embed day_03/data.txt
var Day03Data string var Day03Data string
//go:embed day_04/data.txt
var Day04Data string

View File

@ -0,0 +1,10 @@
MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX

140
day_04/data.txt Normal file
View File

@ -0,0 +1,140 @@
XMASAXMASXXMMAMAXAXXXMSASXSXSXMAMMAMXMASASXMXMASMSMSSMMSXMASXMSMXMASMMSSMMMSMMAMMSMMMMMSXMAXMSMMMMMSAXAXXXMASAMXXSXMXSSSMSMSXMAMXXXSAXSMSAMX
MSMMMMSMXMXSSSSSSMSMSMSASAAXXASAXXMAXSMSAMMSAMSXAAAAXSAMXMASXMXMASAMXXAAAXMAMMAAMAMXAASAMMMSAMXMAASMSXMSMSMXMASMXMASXMAAXAAAXXSSSMMAMMXAXSXX
AAAAAAAMMSAAMAAAXAAAAAMMMMMXMXMASXMSASXMAMAMASAMSMMMXMXSAMXSXMASXSAMXMSSMMSASXXSSMMSAMMASAAAAXXXSMSAAMXAAMSXSAMASAAMAMAMSMSMSMAAASAAXAMXMMMS
SSSMMSSSSMSSMMMMMSMXMMMAAXXAXAMXMXAMASMSMMMSMMMXASAMXSMSXSAMAXAMAMASAMXAXXMAMXAAMXXMXMMAMMSSSMXXXAMXMAMMSMAXMASXXMASMMAXAAAXAAMMMMSXXSAMXAAA
XMAXMXXMAAAXXXAMXXSMMMSMMSAMXMMMMMXMXMAAMAASAMXSAXXMAXAMXMMSSMSSSSMMASXMMMMAMSSMSMMAAXMASXAAAAASMMMSXSXAXMAMSAMXSSMSXMAMMXMSMSSXSAMXAAXXSMSS
XMASMMASMMMSSSMMSAMXSAAAAAX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AAXXMASXSMSMSMMMAMXXAXXMM
MXMAMMAMMAMAMSSMXSAASXSSMSMAMAAAMXMMMAMSMMMMXMASMASMSMMAMAXXAXASMSMXMSSMMXMAXMMMMMMMASAAMAMMASAAMXSAXMMSSXSASAASXXSSSSXAXXAAMMMXASMSMSMSSSMS
XXMAXSASMSSMXAAXAXSASAMMAAMAMMMMXAMAMXMXXMAMMXXXSAMXAASXSMSXMMMAXAASAAAXSMSSMASAMXSAMMMMMAXSAXMSMMMMMXMAMXMAMXSMSAXAMXMXMMSMMSAMAMAXAAAMAXAS
MXXMXXASAMAMSSSMXMAXMAMMSMSMMSASMSSSSSMXSSSSMMMMMMMMSXMAAASMSASASMXMMMSMMAAMXAMASMMMXSAXXAMMASAMAMAAMXMASMMSSXXAMXMAMAMAMAMSAMXMAMAMMMMMAMSM
SAASMMXMAMSMAAAAXXMASAMXAAAAXMASAAAAAMXAMXAAAAAAAAXXXMASMXMASASAMXXXXMAAMMMSMMSAMAAXASMSXMAMAAASAMAMSAMXSXAAAAMMMAAASASASMMMMSAMAMXSSXMMXSAM
MXSAAASMXMAMXSMMMXXASASXMSMSMMXMXMMMAMMASMSMMSSSSSMSAMXXXXMAMXMXMSAMXSSSMSAMXAMXSSMMASAXXAXMMSXSMSAMXAXMSMXSMSMXSSSMSMSASAMXXSXSXSAMXSAMXMAS

10
day_04/example_data.txt Normal file
View File

@ -0,0 +1,10 @@
MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX

130
day_04/solution.go Normal file
View File

@ -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'
}

27
day_04/solution_test.go Normal file
View File

@ -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)
}
}

View File

@ -4,6 +4,7 @@ import (
"advent_of_code_2024/day_01" "advent_of_code_2024/day_01"
"advent_of_code_2024/day_02" "advent_of_code_2024/day_02"
"advent_of_code_2024/day_03" "advent_of_code_2024/day_03"
"advent_of_code_2024/day_04"
_ "embed" _ "embed"
"fmt" "fmt"
"os" "os"
@ -25,6 +26,10 @@ func main() {
fmt.Printf("Day 03. Basic: %d\n", day_03.SolveBasic(Day03Data)) // 189527826 fmt.Printf("Day 03. Basic: %d\n", day_03.SolveBasic(Day03Data)) // 189527826
case "03-complex": case "03-complex":
fmt.Printf("Day 03. Complex: %d\n", day_03.SolveComplex(Day03Data)) // 63013756 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
} }
} }