day02
This commit is contained in:
parent
dfc8b450fb
commit
c026df5d0a
61
day02/day02.go
Normal file
61
day02/day02.go
Normal 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
|
||||
}
|
||||
2
inputs/2_test
Normal file
2
inputs/2_test
Normal file
@ -0,0 +1,2 @@
|
||||
2x3x4
|
||||
1x1x10
|
||||
4
main.go
4
main.go
@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"aoc2015/aoclib"
|
||||
"aoc2015/day01"
|
||||
"aoc2015/day02"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -22,6 +23,9 @@ func initDayFunctions() {
|
||||
dayFunctions[1] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
|
||||
dayFunctions[1][1] = day01.Part1
|
||||
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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user