This commit is contained in:
Stefan Harmuth 2020-12-31 10:37:23 +01:00
parent 6aa66b4f6f
commit 81562d7441
4 changed files with 58 additions and 0 deletions

54
day20/day.go Normal file
View File

@ -0,0 +1,54 @@
package day20
import (
"math"
"tools"
)
func Part1(puzzle tools.AoCPuzzle) interface{} {
target := puzzle.GetInputArrayInt()[0]
presents := 0
houseNumber := 0
for presents < target {
houseNumber++
divisor := tools.NewSet()
for i := 1; i <= int(math.Sqrt(float64(houseNumber))); i++ {
if houseNumber%i == 0 {
divisor.Add(i)
divisor.Add(houseNumber / i)
}
}
presents = 0
for v := range divisor {
presents += v.(int) * 10
}
}
return houseNumber
}
func Part2(puzzle tools.AoCPuzzle) interface{} {
target := puzzle.GetInputArrayInt()[0]
presents := 0
houseNumber := 0
for presents < target {
houseNumber++
divisor := tools.NewSet()
for i := 1; i <= int(math.Sqrt(float64(houseNumber))); i++ {
if houseNumber%i == 0 {
divisor.Add(houseNumber / i)
}
}
presents = 0
for v := range divisor {
if houseNumber/v.(int) < 50 {
presents += v.(int) * 11
}
}
}
return houseNumber
}

1
inputs/20 Normal file
View File

@ -0,0 +1 @@
34000000

1
inputs/20_test Normal file
View File

@ -0,0 +1 @@
4650

View File

@ -20,6 +20,7 @@ import (
"aoc2015/day17" "aoc2015/day17"
"aoc2015/day18" "aoc2015/day18"
"aoc2015/day19" "aoc2015/day19"
"aoc2015/day20"
"flag" "flag"
"fmt" "fmt"
"os" "os"
@ -56,6 +57,7 @@ func initDayFunctions() {
17: {1: day17.Part1, 2: day17.Part2}, 17: {1: day17.Part1, 2: day17.Part2},
18: {1: day18.Part1, 2: day18.Part2}, 18: {1: day18.Part1, 2: day18.Part2},
19: {1: day19.Part1, 2: day19.Part2}, 19: {1: day19.Part1, 2: day19.Part2},
20: {1: day20.Part1, 2: day20.Part2},
} }
} }