day20
This commit is contained in:
parent
6aa66b4f6f
commit
81562d7441
54
day20/day.go
Normal file
54
day20/day.go
Normal 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_test
Normal file
1
inputs/20_test
Normal file
@ -0,0 +1 @@
|
|||||||
|
4650
|
||||||
2
main.go
2
main.go
@ -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},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user