This commit is contained in:
Stefan Harmuth 2020-12-21 21:28:31 +01:00
parent 36746b69e4
commit dfc8b450fb
4 changed files with 38 additions and 18 deletions

34
day01/day01.go Normal file
View File

@ -0,0 +1,34 @@
package day01
import "aoc2015/aoclib"
func Part1(puzzle aoclib.Puzzle) interface{} {
line := puzzle.GetInputArray()[0]
answer := 0
for _, c := range line {
if c == '(' {
answer++
} else {
answer--
}
}
return answer
}
func Part2(puzzle aoclib.Puzzle) interface{} {
line := puzzle.GetInputArray()[0]
answer := 0
for x, c := range line {
if c == '(' {
answer++
} else {
answer--
}
if answer < 0 {
return x + 1
}
}
return -1
}

1
inputs/1 Normal file

File diff suppressed because one or more lines are too long

1
inputs/1_test Normal file
View File

@ -0,0 +1 @@
(())()()))(((((())

20
main.go
View File

@ -1,12 +1,8 @@
package main package main
import ( import (
"aoc2020/aoclib" "aoc2015/aoclib"
"aoc2020/day01" "aoc2015/day01"
"aoc2020/day02"
"aoc2020/day03"
"aoc2020/day17"
"aoc2020/day18"
"flag" "flag"
"fmt" "fmt"
"os" "os"
@ -26,18 +22,6 @@ func initDayFunctions() {
dayFunctions[1] = make(map[int]func(puzzle aoclib.Puzzle) interface{}) dayFunctions[1] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[1][1] = day01.Part1 dayFunctions[1][1] = day01.Part1
dayFunctions[1][2] = day01.Part2 dayFunctions[1][2] = day01.Part2
dayFunctions[2] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[2][1] = day02.Part1
dayFunctions[2][2] = day02.Part2
dayFunctions[3] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[3][1] = day03.Part1
dayFunctions[3][2] = day03.Part2
dayFunctions[17] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[17][1] = day17.Part1
dayFunctions[17][2] = day17.Part2
dayFunctions[18] = make(map[int]func(puzzle aoclib.Puzzle) interface{})
dayFunctions[18][1] = day18.Part1
dayFunctions[18][2] = day18.Part2
} }
func execute(thisDay int) { func execute(thisDay int) {