Day 3 Part 1
parent
5dc42aa8e6
commit
3c371cbedf
|
|
@ -3,5 +3,7 @@
|
||||||
Este es mi intento para resolver todos¹ los problemas del [AOC 2025](https://adventofcode.com/).
|
Este es mi intento para resolver todos¹ los problemas del [AOC 2025](https://adventofcode.com/).
|
||||||
|
|
||||||
Día 1: Rust
|
Día 1: Rust
|
||||||
|
Día 2: Python
|
||||||
|
Día 3: Go
|
||||||
|
|
||||||
¹ Ojalá
|
¹ Ojalá
|
||||||
|
|
|
||||||
|
|
@ -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()
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue