🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 11 Min Lesezeit
0

Advent of Code Day 4 in Golang: Searching XMAS and X-MAS

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




Introduction



Moving on to day 4, we have a grid problem in front of us, we are given some numbers in the form of a grid, i.e. some rows and columns with some upper case letters. What we need to do is to find is the word XMAS in any direction (up, left, down, right, diagonals), and in the second part we need to find the word MAS forming an X.



So, let’s see how we can approach this and solve it in golang.



You can check out my solutions







GitHub logo



Advent of Code









Constructing the grid



The most fundamental part of the problem lies in actually converting the text into a grid or a matrix form. We can split the lines, into individual lines and append each character as an element in a list, and that way we can have a list of list of strings which is a matrix or grid-like (2-dimensional) structure.



So, below is the input for the puzzle.




CODE
MMMSXXMASM
MSAMXMSMSA
AMXSXMAAMM
MSAMASMSMX
XMASAMXAMM
XXAMMXXAMA
SMSMSASXSS
SAXAMASAAA
MAMMMXMMMM
MXMXAXMASX






We need to convert it into something like this




CODE
[
[M M M S X X M A S M]
[M S A M X M S M S A]
[A M X S X M A A M M]
[M S A M A S M S M X]
[X M A S A M X A M M]
[X X A M M X X A M A]
[S M S M S A S X S S]
[S A X A M A S A A A]
[M A M M M X M M M M]
[M X M X A X M A S X]
]






So, this is a list of strings, we can say in golang it is a [][]string . We can do that by creating a function like this:




CODE
func ConstructGrid(lines []string) [][]string {
grid := [][]string{}
for _, line := range lines {
row := []string{}
for _, char := range strings.Split(line, "") {
row = append(row, char)
}
grid = append(grid, row)
}
return grid
}






The above function takes in a list of strings and returns a list of list of strings that are individual letters in the grid.


We can read the file bytes and split the bytes on newline characters and then this will be used as the input for this function.



So, once the input is parsed into a grid, we can start thinking about the actual logic of finding the word XMAS in it.





Part 1



So, in the first part, we need to find the word XMAS in the matrix which could be appearing:




  • forwards (as XMAS)


  • backward (as SAMX)


  • upwards




CODE
            S
A
M
X






  • downwards



CODE
            X
M
A
S






  • Diagonal upwards (right or up left)



CODE
            S
A
M
X

OR
S
A
M
X






  • Diagonals downwards (right or left)



CODE
                     X
M
A
S

OR

X
M
A
S






So, there are 8 directions where XMAS could appear in the grid, there could n number of these XMAS . We need to find the count of these in the grid.



.






Conclusion



So, that is it from day 4 of Advent of Code in Golang, let me know if you have any suggestions, and how you approached it. any better solutions?



Happy Coding :)

Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Advent of Code Day 4 in Golang: Searching XMAS and X-MAS

Thematisch verwandte Begriffe: Advent, Code, Golang, Searching · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...