Compare commits

..

No commits in common. "82290bad367526e2d03bb8a62d38500174044434" and "93c256d989dc084357ddec77af763de50c8517fd" have entirely different histories.

3 changed files with 3 additions and 94 deletions

12
main.go
View File

@ -10,14 +10,8 @@ func main() {
runAndBenchmark("01", "1", false, solutions.Day01Part01)
runAndBenchmark("01", "2", false, solutions.Day01Part02)
runAndBenchmark("02", "1", false, solutions.Day02Part01)
runAndBenchmark("02", "2", false, solutions.Day02Part02)
runAndBenchmark("03", "1", false, solutions.Day03Part01)
runAndBenchmark("03", "2", false, solutions.Day03Part02)
runAndBenchmark("04", "1", false, solutions.Day04Part01)
runAndBenchmark("04", "2", false, solutions.Day04Part02)
runAndBenchmark("02", "1", false, solutions.Day01Part01)
runAndBenchmark("02", "2", false, solutions.Day01Part02)
}
type execute func(bool) int
@ -27,5 +21,5 @@ func runAndBenchmark(day, part string, isTest bool, fn execute) {
computation := fn(isTest)
endMs := time.Now().UnixMicro()
duration := endMs - startMs
fmt.Printf("Day %s part %s:\t%12d\t%5d micros.\n", day, part, computation, duration)
fmt.Printf("Day %s part %s:\t%10d\t%5d micros.\n", day, part, computation, duration)
}

View File

@ -1,44 +0,0 @@
package solutions
import "strings"
func countTrees(input string, right, down int) int {
verticalPos := down
horizontalPos := right
lines := strings.Split(input, "\n")
width := len(lines[0])
treesCount := 0
for verticalPos < len(lines) {
line := lines[verticalPos]
charAt := string(line[horizontalPos])
if charAt == "#" {
treesCount += 1
}
horizontalPos += right
horizontalPos = horizontalPos % width
verticalPos += down
}
return treesCount
}
func Day03Part01(isTest bool) int {
input := ReadInput("03", isTest)
return countTrees(input, 3, 1)
}
func Day03Part02(isTest bool) int {
input := ReadInput("03", isTest)
amount1 := countTrees(input, 1, 1)
amount2 := countTrees(input, 3, 1)
amount3 := countTrees(input, 5, 1)
amount4 := countTrees(input, 7, 1)
amount5 := countTrees(input, 1, 2)
return amount1 * amount2 * amount3 * amount4 * amount5
}

View File

@ -1,41 +0,0 @@
package solutions
import (
"regexp"
"strings"
)
func Day04Part01(isTest bool) int {
input := ReadInput("04", isTest)
passports := strings.Split(input, "\n\n")
regex, _ := regexp.Compile("(\\w+:[\\w#]+)")
correctAmount := 0
for _, passport := range passports {
matches := regex.FindAllString(passport, -1)
values := make(map[string]string)
for _, match := range matches {
colonPosition := strings.Index(match, ":")
key := match[:colonPosition]
value := match[colonPosition+1:]
values[key] = value
}
_, cidMissing := values["cid"]
keysAmount := len(values)
if keysAmount == 8 || (keysAmount == 7 && !cidMissing) {
correctAmount += 1
}
}
return correctAmount
}
func Day04Part02(isTest bool) int {
return -1
}