mirror of
https://github.com/Threnklyn/advent-of-code-go.git
synced 2026-06-07 20:53:30 +02:00
might be making a mistake starting 2018...
This commit is contained in:
@@ -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 |
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -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)
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user