might be making a mistake starting 2018...

This commit is contained in:
alexchao26
2020-09-06 20:12:08 -04:00
parent 6508ec81d4
commit 3aa2b3e09a
104 changed files with 1100 additions and 0 deletions
+11
View File
@@ -0,0 +1,11 @@
# Advent of Code 2018
Language: GoLang.
[https://adventofcode.com/2018](https://adventofcode.com/2018)
---
## Summary
Day | Name | Type of Algo & Notes
--- | --- | ---
1 | Chronal Calibration | - Pretty simple, direct math problem
2 |
+1028
View File
File diff suppressed because it is too large Load Diff
+27
View File
@@ -0,0 +1,27 @@
package main
import (
"adventofcode/util"
"fmt"
"strconv"
"strings"
)
func main() {
input := util.ReadFile("../input.txt")
sli := strings.Split(input, "\n")
var sum int
for _, instruction := range sli {
sign := instruction[:1]
num, _ := strconv.Atoi(instruction[1:])
if sign == "+" {
sum += num
} else {
sum -= num
}
}
fmt.Println("Final sum", sum)
}
+34
View File
@@ -0,0 +1,34 @@
package main
import (
"adventofcode/util"
"fmt"
"strconv"
"strings"
)
func main() {
input := util.ReadFile("../input.txt")
sli := strings.Split(input, "\n")
var sum int
seen := make(map[int]bool)
for {
for _, instruction := range sli {
sign := instruction[:1]
num, _ := strconv.Atoi(instruction[1:])
if sign == "+" {
sum += num
} else {
sum -= num
}
if seen[sum] {
fmt.Println("Number seen twice is:", sum)
return
}
seen[sum] = true
}
}
}