-
Notifications
You must be signed in to change notification settings - Fork 0
/
day11_1.go
56 lines (44 loc) · 1.03 KB
/
day11_1.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package day11
import (
"strconv"
"strings"
"github.com/blfuentes/AdventOfCode_2024_Go/utilities"
)
func MutateStone(stone int) []int {
if stone == 0 {
return []int{1}
}
if len(strconv.Itoa(stone))%2 == 0 {
left, right := utilities.SplitNumberInTwo(stone)
return []int{left, right}
}
return []int{stone * 2024}
}
func Blink1(numoOfBlinks int, stones *[]int) int {
doBlink := func(blink int) {
for blink > 0 {
newstones := make([]int, 0)
for _, s := range *stones {
newstones = append(newstones, MutateStone(s)...)
}
stones = &newstones
blink--
}
}
doBlink(numoOfBlinks)
return len(*stones)
}
func Executepart1() int {
var result int = 0
var fileName string = "./day11/day11.txt"
if fileContent, err := utilities.ReadFileAsText(fileName); err == nil {
parts := strings.Split(fileContent, " ")
numStones := len(parts)
stones := make([]int, numStones)
for idx := 0; idx < numStones; idx++ {
stones[idx] = utilities.StringToInt(parts[idx])
}
result = Blink1(25, &stones)
}
return result
}