File tree Expand file tree Collapse file tree 3 files changed +110
-0
lines changed
Expand file tree Collapse file tree 3 files changed +110
-0
lines changed Original file line number Diff line number Diff line change 1+ input :
2+ http " https://adventofcode.com/2025/day/1/input" " Cookie:session=${AOC_SESSION} ;" > input
3+
4+ main1 :
5+ go build -o main1 main1.go
6+
7+ main2 :
8+ go build -o main2 main2.go
9+
10+ .PHONY : run1 run2 clean
11+
12+ run1 : main1 input
13+ ./main1 < input
14+
15+ run2 : main2 input
16+ ./main2 < input
17+
18+ clean :
19+ rm -f main1 main2 input
20+
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "bufio"
5+ "fmt"
6+ "os"
7+ "strconv"
8+ )
9+
10+ func main () {
11+
12+ var (
13+ pos = 50
14+ count = 0
15+ )
16+
17+ for scanner := bufio .NewScanner (os .Stdin ); scanner .Scan (); {
18+ line := scanner .Text ()
19+
20+ steps , _ := strconv .Atoi (line [1 :])
21+
22+ // ignore the loops and keep only the meaningful steps
23+ steps = steps % 100
24+
25+ if line [0 ] == 'L' {
26+ steps *= - 1
27+ }
28+
29+ pos = (pos + steps + 100 ) % 100
30+
31+ if pos == 0 {
32+ count ++
33+ }
34+ }
35+
36+ fmt .Println (count )
37+ }
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "bufio"
5+ "fmt"
6+ "os"
7+ "strconv"
8+ )
9+
10+ func main () {
11+
12+ var (
13+ pos = 50
14+ oldPos = 50
15+ count = 0
16+ )
17+
18+ for scanner := bufio .NewScanner (os .Stdin ); scanner .Scan (); {
19+ line := scanner .Text ()
20+ steps , _ := strconv .Atoi (line [1 :])
21+
22+ // full loops of the command itself
23+ count += steps / 100
24+
25+ // ignore the loops and keep only the meaningful steps
26+ steps = steps % 100
27+
28+ if line [0 ] == 'L' {
29+ steps *= - 1
30+ }
31+
32+ oldPos = pos
33+ pos += steps
34+
35+ switch {
36+ case pos == 0 :
37+ count ++
38+
39+ case pos < 0 :
40+ // If I'm starting from 0, I should not count the passage
41+ if oldPos != 0 {
42+ count ++
43+ }
44+ pos += 100
45+
46+ case pos > 99 :
47+ count ++
48+ pos -= 100
49+ }
50+ }
51+
52+ fmt .Println (count )
53+ }
You can’t perform that action at this time.
0 commit comments