Implemtend Day 01 of 2025 with Golang

This commit is contained in:
2025-06-05 10:52:18 +02:00
parent f40eda99dd
commit f69d4e14ad
6 changed files with 70 additions and 0 deletions

0
2015/1/README.md Normal file
View File

1
2015/1/example.txt Normal file
View File

@@ -0,0 +1 @@
))(((((

10
2015/1/golang/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,10 @@
{
"[go]": {
"editor.insertSpaces": false,
"editor.formatOnSave": true,
"editor.defaultFormatter": "golang.go",
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
}
}

3
2015/1/golang/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module aoc/day-1
go 1.24.3

55
2015/1/golang/main.go Normal file
View File

@@ -0,0 +1,55 @@
package main
import (
"fmt"
"os"
"strings"
)
func main() {
data := readFile("../input.txt")
characters := strings.Split(data, "")
part1 := part1(characters)
part2 := part2(characters)
fmt.Printf("Part 1: %d\n", part1)
fmt.Printf("Part 2: %d\n", part2)
}
func part1(input []string) int {
floorLevel := 0
for _, v := range input {
switch v {
case "(":
floorLevel += 1
default:
floorLevel -= 1
}
}
return floorLevel
}
func part2(input []string) int {
floorLevel := 0
position := 0
for i, v := range input {
switch v {
case "(":
floorLevel += 1
default:
floorLevel -= 1
}
if floorLevel == -1 {
position = i + 1
break
}
}
return position
}
func readFile(filename string) string {
content, err := os.ReadFile(filename)
if err != nil {
return ""
}
return string(content)
}

1
2015/1/input.txt Normal file

File diff suppressed because one or more lines are too long