aboutsummaryrefslogtreecommitdiff
path: root/2015/20/puzzles.go
diff options
context:
space:
mode:
authorThomas Voss <thomasvoss@live.com> 2021-11-06 13:34:27 +0100
committerThomas Voss <thomasvoss@live.com> 2021-11-06 13:34:27 +0100
commitdafb3e27313470cd4cea664b24cd5dae6689d7d7 (patch)
tree17f8c76c450fb682ccaa97757c2e3ab32997befc /2015/20/puzzles.go
parentf61b65581c30879a9bfa43ffafb99d4ba160cd32 (diff)
Add 2015 Day 20 solutions
Diffstat (limited to '2015/20/puzzles.go')
-rw-r--r--2015/20/puzzles.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/2015/20/puzzles.go b/2015/20/puzzles.go
new file mode 100644
index 0000000..5f2d37f
--- /dev/null
+++ b/2015/20/puzzles.go
@@ -0,0 +1,58 @@
+package main
+
+import (
+ "fmt"
+ "math"
+ "os"
+)
+
+func calc(n int) int {
+ acc := 0
+ s := math.Sqrt(float64(n))
+
+ if s == math.Trunc(s) {
+ acc += int(s)
+ } else {
+ s = math.Ceil(s)
+ }
+
+ for i := 1; i < int(s); i++ {
+ if n % i == 0 {
+ /* START PART 2 */
+ ndi := n / i
+ if ndi <= 50 {
+ acc += i + ndi
+ } else if i <= 50 {
+ acc += ndi
+ }
+ /* END PART 2 START PART 1 */
+ acc += i + n / i
+ /* END PART 1 */
+ }
+ }
+
+ return acc
+}
+
+func main() {
+ file, err := os.Open("input")
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "%s: %s\n", os.Args[0], err)
+ os.Exit(1)
+ }
+
+ var n int
+ fmt.Fscanf(file, "%d", &n)
+ /* START PART 2 */
+ sn := n / 11
+ /* END PART 2 START PART 1 */
+ sn := n / 10
+ /* END PART 1 */
+
+ for i := 1; i <= n; i++ {
+ if calc(i) >= sn {
+ fmt.Println(i)
+ break
+ }
+ }
+}