From 67498cd5d0d0c082f4399b41121fd2dff85c7e8a Mon Sep 17 00:00:00 2001 From: tiennm99 Date: Mon, 1 Dec 2025 21:26:59 +0700 Subject: [PATCH] feat(2025): add day 1 part1 --- .gitignore | 4 ++++ 2025/day/1/part1.go | 33 +++++++++++++++++++++++++++++++++ go.mod | 3 +++ 3 files changed, 40 insertions(+) create mode 100644 2025/day/1/part1.go create mode 100644 go.mod diff --git a/.gitignore b/.gitignore index aaadf73..089a213 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +.idea + + + # If you prefer the allow list template instead of the deny list, see community template: # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore # diff --git a/2025/day/1/part1.go b/2025/day/1/part1.go new file mode 100644 index 0000000..747e085 --- /dev/null +++ b/2025/day/1/part1.go @@ -0,0 +1,33 @@ +package main + +import ( + "bufio" + "fmt" + "os" + "strconv" +) + +func main() { + file, _ := os.Open("input.txt") + defer file.Close() + + scanner := bufio.NewScanner(file) + current := 50 + counter := 0 + for scanner.Scan() { + line := scanner.Text() + direction := line[0] + multiplier := 1 + if direction == 'L' { + multiplier = -1 + } + number, _ := strconv.Atoi(line[1:]) + current += number * multiplier + current = ((current % 100) + 100) % 100 + if current == 0 { + counter++ + } + // fmt.Printf("%s %c %d %d %d %d\n", line, direction, number, multiplier, current, counter) + } + fmt.Printf("%d\n", counter) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..567358a --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/tiennm99/adventofcode + +go 1.23.4