This commit is contained in:
Stefan Harmuth 2020-12-21 21:48:52 +01:00
parent dfc8b450fb
commit c026df5d0a
4 changed files with 1067 additions and 0 deletions

61
day02/day02.go Normal file
View File

@ -0,0 +1,61 @@
package day02
import (
"aoc2015/aoclib"
"strconv"
"strings"
)
func Part1(puzzle aoclib.Puzzle) interface{} {
sqm := 0
for _, line := range puzzle.GetInputArray() {
dim := strings.Split(line, "x")
l, _ := strconv.Atoi(dim[0])
w, _ := strconv.Atoi(dim[1])
h, _ := strconv.Atoi(dim[2])
sqm += 2*l*w + 2*w*h + 2*h*l
if l <= w {
if w <= h {
sqm += l * w
} else {
sqm += l * h
}
} else {
if l <= h {
sqm += w * l
} else {
sqm += w * h
}
}
}
return sqm
}
func Part2(puzzle aoclib.Puzzle) interface{} {
length := 0
for _, line := range puzzle.GetInputArray() {
dim := strings.Split(line, "x")
l, _ := strconv.Atoi(dim[0])
w, _ := strconv.Atoi(dim[1])
h, _ := strconv.Atoi(dim[2])
length += l * w * h
if l <= w {
if w <= h {
length += 2*l + 2*w
} else {
length += 2*l + 2*h
}
} else {
if l <= h {
length += 2*w + 2*l
} else {
length += 2*w + 2*h
}
}
}
return length
}

1000
inputs/2 Normal file

File diff suppressed because it is too large Load Diff

2
inputs/2_test Normal file
View File

@ -0,0 +1,2 @@
2x3x4
1x1x10

View File

@ -3,6 +3,7 @@ package main
import ( import (
"aoc2015/aoclib" "aoc2015/aoclib"
"aoc2015/day01" "aoc2015/day01"
"aoc2015/day02"
"flag" "flag"
"fmt" "fmt"
"os" "os"
@ -22,6 +23,9 @@ func initDayFunctions() {
dayFunctions[1] = make(map[int]func(puzzle aoclib.Puzzle) interface{}) dayFunctions[1] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[1][1] = day01.Part1 dayFunctions[1][1] = day01.Part1
dayFunctions[1][2] = day01.Part2 dayFunctions[1][2] = day01.Part2
dayFunctions[2] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[2][1] = day02.Part1
dayFunctions[2][2] = day02.Part2
} }
func execute(thisDay int) { func execute(thisDay int) {