From 6720bbabc1464c9d114afb2afe69d4abe0ec19d9 Mon Sep 17 00:00:00 2001 From: Kharec Date: Mon, 8 Dec 2025 22:34:59 +0100 Subject: [PATCH] feat: solve part one building the code digit by digit --- internal/2016/DayTwo/code.go | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 internal/2016/DayTwo/code.go diff --git a/internal/2016/DayTwo/code.go b/internal/2016/DayTwo/code.go new file mode 100644 index 0000000..f599db7 --- /dev/null +++ b/internal/2016/DayTwo/code.go @@ -0,0 +1,57 @@ +package daytwo + +import ( + "advent-of-code/internal/registry" + "os" + "strings" +) + +func init() { + registry.Register("2016D2", ParseInput, PartOne, PartTwo) +} + +func ParseInput(filepath string) []string { + content, _ := os.ReadFile(filepath) + return strings.Split(string(content), "\n") +} + +func PartOne(instructions []string) int { + row, column := 1, 1 + + keypad := [3][3]int{ + {1, 2, 3}, + {4, 5, 6}, + {7, 8, 9}, + } + code := 0 + + for _, line := range instructions { + for _, move := range line { + switch move { + case 'U': + if row > 0 { + row-- + } + case 'D': + if row < 2 { + row++ + } + case 'L': + if column > 0 { + column-- + } + case 'R': + if column < 2 { + column++ + } + } + } + code = code*10 + keypad[row][column] + } + + return code +} + +func PartTwo(data []string) int { + return 0 +}