mirror of
https://github.com/tiennm99/adventofcode.git
synced 2026-10-15 06:15:56 +00:00
feat(2025: add day 1 part 2
This commit is contained in:
1 parent
7788554da9
commit
7f49236d21
2 files changed
+37
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
module part2
|
||||||
|
|
||||||
|
go 1.23.4
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
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:])
|
||||||
|
for range number {
|
||||||
|
current += multiplier
|
||||||
|
current = ((current % 100) + 100) % 100
|
||||||
|
if current == 0 {
|
||||||
|
counter++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Printf("%d\n", counter)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user