104 lines
1.3 KiB
Go
104 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"bufio"
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func mustAtoi(line string) int {
|
|
i, _ := strconv.Atoi(line)
|
|
return i
|
|
}
|
|
|
|
func main() {
|
|
start := time.Now()
|
|
partOne()
|
|
duration := time.Since(start)
|
|
partTwo()
|
|
duration2 := time.Since(start)
|
|
fmt.Printf("p1: %s, p2: %s\n", duration, duration2-duration)
|
|
}
|
|
|
|
func makeScanner(test bool) *bufio.Scanner {
|
|
var f *os.File
|
|
if test {
|
|
f, _ = os.Open("inputs/testinput")
|
|
} else {
|
|
f, _ = os.Open("inputs/input")
|
|
}
|
|
reader := bufio.NewReader(f)
|
|
return bufio.NewScanner(reader)
|
|
}
|
|
|
|
type thing interface {
|
|
IsNum() bool
|
|
Num() int
|
|
IsList() bool
|
|
List() list
|
|
}
|
|
|
|
type list struct {
|
|
children []thing
|
|
}
|
|
|
|
func (_ list) IsNum() bool {
|
|
return false
|
|
}
|
|
|
|
func (n list) Num() int {
|
|
panic("oops")
|
|
}
|
|
|
|
func (_ list) IsList() bool {
|
|
return true
|
|
}
|
|
|
|
func (l list) List() list {
|
|
return l
|
|
}
|
|
|
|
func (l list) Len() int {
|
|
return len(l.children)
|
|
}
|
|
|
|
type num int
|
|
|
|
func (_ num) IsNum() bool {
|
|
return true
|
|
}
|
|
|
|
func (n num) Num() int {
|
|
return int(n)
|
|
}
|
|
|
|
func (_ num) IsList() bool {
|
|
return false
|
|
}
|
|
|
|
func (_ num) List() list {
|
|
panic("oops")
|
|
}
|
|
|
|
func partOne() {
|
|
scanner := makeScanner(false)
|
|
|
|
pairCount := 0
|
|
sum := 0
|
|
|
|
for scanner.Scan() {
|
|
left := scanner.Text()
|
|
right := scanner.Text()
|
|
}
|
|
}
|
|
|
|
func partTwo() {
|
|
scanner := makeScanner(false)
|
|
|
|
for scanner.Scan() {
|
|
// line := scanner.Text()
|
|
}
|
|
}
|