diff --git a/README.md b/README.md index c23297a..2f7e934 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,7 @@ Este es mi intento para resolver todos¹ los problemas del [AOC 2025](https://adventofcode.com/). Día 1: Rust +Día 2: Python +Día 3: Go ¹ Ojalá diff --git a/day-3/main.go b/day-3/main.go new file mode 100644 index 0000000..c39ace0 --- /dev/null +++ b/day-3/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "os" + "strconv" + "strings" +) + +func check(e error) { + if e != nil { + panic(e) + } +} + +func parseInput() []string { + raw_data, err := os.ReadFile("input.txt") + check(err) + data := string(raw_data[:]) + lines := strings.Split(strings.TrimSpace(data), "\n") + return lines +} + +func part1() { + output := 0 + for _, bank := range parseInput() { + max := 0 + for i, n1 := range bank[:len(bank)-1] { + for _, n2 := range bank[i+1:] { + new_value, err := strconv.Atoi(string(n1) + string(n2)) + check(err) + if new_value > max { + max = new_value + } + } + } + output = output + max + } + fmt.Println(output) +} + +func main() { + fmt.Println("Part 1:") + part1() +}