Skip to content

Commit c8f5399

Browse files
D1 P1+2 and D2 P1 in go (#38)
* Day One with go * Day Two Part One in go * Update Day-01/go/artur/day01.go Co-authored-by: das_ <[email protected]> * Update Day-02/go/artur/day02.go Co-authored-by: das_ <[email protected]> --------- Co-authored-by: das_ <[email protected]>
1 parent 6ad3cc1 commit c8f5399

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

Day-01/go/artur/day01.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"strconv"
6+
"strings"
7+
)
8+
9+
func main() {
10+
input, _ := os.ReadFile("input01.txt")
11+
lines := strings.Split(string(input), "\n")
12+
13+
countP1 := 0
14+
countP2 := 0
15+
dial := int64(50)
16+
for _, line := range lines {
17+
increase, _ := strconv.ParseInt(line[1:], 10, 64)
18+
19+
for ; increase != 0; increase-- {
20+
if line[0] == 'R' {
21+
dial = (dial + 1) % 100
22+
} else {
23+
dial = (dial - 1) % 100
24+
}
25+
if dial == 0 {
26+
countP2++
27+
}
28+
}
29+
if dial == 0 {
30+
countP1++
31+
}
32+
}
33+
println(countP1)
34+
println(countP2)
35+
}

Day-02/go/artur/day02.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"strconv"
6+
"strings"
7+
)
8+
9+
func main() {
10+
input, _ := os.ReadFile("input02.txt")
11+
doubleIds := strings.Split(string(input), ",")
12+
result := 0
13+
for _, idRange := range doubleIds {
14+
idSplit := strings.Split(idRange, "-")
15+
id1, _ := strconv.Atoi(idSplit[0])
16+
id2, _ := strconv.Atoi(idSplit[1])
17+
for ; id1 <= id2; id1++ {
18+
id1String := strconv.Itoa(id1)
19+
if len(id1String)%2 == 1 {
20+
continue
21+
}
22+
if id1String[:len(id1String)/2] == id1String[len(id1String)/2:] {
23+
result += id1
24+
}
25+
}
26+
}
27+
println(result)
28+
}

0 commit comments

Comments
 (0)