feat(2025): add day 1 part1

This commit is contained in:
2025-12-01 21:26:59 +07:00
parent e647e6d99c
commit 67498cd5d0
3 changed files with 40 additions and 0 deletions
+4
View File
@@ -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
#
+33
View File
@@ -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)
}
+3
View File
@@ -0,0 +1,3 @@
module github.com/tiennm99/adventofcode
go 1.23.4