mirror of
https://github.com/tiennm99/adventofcode.git
synced 2026-06-17 16:48:02 +00:00
feat(2025): add day 1 part1
This commit is contained in:
@@ -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
|
||||
#
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user