diff options
author | Thomas Voss <thomasvoss@live.com> | 2021-11-06 13:34:27 +0100 |
---|---|---|
committer | Thomas Voss <thomasvoss@live.com> | 2021-11-06 13:34:27 +0100 |
commit | dafb3e27313470cd4cea664b24cd5dae6689d7d7 (patch) | |
tree | 17f8c76c450fb682ccaa97757c2e3ab32997befc /2015 | |
parent | f61b65581c30879a9bfa43ffafb99d4ba160cd32 (diff) |
Add 2015 Day 20 solutions
Diffstat (limited to '2015')
-rw-r--r-- | 2015/20/.gitignore | 1 | ||||
-rw-r--r-- | 2015/20/Makefile | 12 | ||||
-rw-r--r-- | 2015/20/input | 1 | ||||
-rw-r--r-- | 2015/20/puzzles.go | 58 |
4 files changed, 72 insertions, 0 deletions
diff --git a/2015/20/.gitignore b/2015/20/.gitignore new file mode 100644 index 0000000..60d075d --- /dev/null +++ b/2015/20/.gitignore @@ -0,0 +1 @@ +puzzle-[12] diff --git a/2015/20/Makefile b/2015/20/Makefile new file mode 100644 index 0000000..8d1d1fa --- /dev/null +++ b/2015/20/Makefile @@ -0,0 +1,12 @@ +all: + sed '/START PART 2/,/END PART 2/d' puzzles.go >tmp1.go + sed '/START PART 1/,/END PART 1/d' puzzles.go >tmp2.go + go build tmp1.go + go build tmp2.go + mv tmp1 puzzle-1 + mv tmp2 puzzle-2 + rm -f tmp[12].go + +.PHONY: clean +clean: + rm -f puzzle-[12] diff --git a/2015/20/input b/2015/20/input new file mode 100644 index 0000000..282bc62 --- /dev/null +++ b/2015/20/input @@ -0,0 +1 @@ +33100000 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 + } + } +} |