4 "adventofcode2022/utils"
9 func Part1(input string) int {
10 lines := strings.Split(input, "\n")
14 for _, line := range lines {
15 cmd := strings.Split(line, " ")
17 case cmd[0] == "noop":
18 strength,cycle = cycles_1(1, cycle, strength, x)
19 case cmd[0] == "addx":
20 strength, cycle = cycles_1(2, cycle, strength, x)
21 x += utils.MustAtoi(cmd[1])
27 func Part2(input string) string {
28 lines := strings.Split(input, "\n")
31 crt := [6][40]string{}
32 for _, line := range lines {
33 cmd := strings.Split(line, " ")
35 case cmd[0] == "noop":
36 cycle = cycles_2(1, cycle, x, &crt)
37 case cmd[0] == "addx":
38 cycle = cycles_2(2, cycle, x, &crt)
39 x += utils.MustAtoi(cmd[1])
45 output = output + crt[i][j]
47 output = output + "\n"
53 func cycles_1(num int, cycle int, strength int, x int) (int, int) {
57 strength = strength + (x * cycle)
58 } else if (cycle - 20) % 40 == 0 {
59 strength = strength + (x * cycle)
62 return strength, cycle
65 func cycles_2(num int, cycle int, x int, crt *[6][40]string) int {
69 if x-1 == crt_y || x == crt_y || x+1 == crt_y {
70 crt[crt_x][crt_y] = "#"
72 crt[crt_x][crt_y] = " "