From dafb3e27313470cd4cea664b24cd5dae6689d7d7 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 6 Nov 2021 13:34:27 +0100 Subject: Add 2015 Day 20 solutions --- 2015/20/puzzles.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 2015/20/puzzles.go (limited to '2015/20/puzzles.go') 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 + } + } +} -- cgit v1.2.3