Refactor some of our tool code.
This commit is contained in:
parent
4cc37c6e39
commit
2614bb2def
|
@ -4,12 +4,12 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserIntMap(os.Args[2])
|
values := util.InputParserIntMap(os.Args[2])
|
||||||
|
|
||||||
switch step {
|
switch step {
|
||||||
case "1":
|
case "1":
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func checkLine(line string, step string) int {
|
func checkLine(line string, step string) int {
|
||||||
|
@ -50,7 +50,7 @@ func checkLine(line string, step string) int {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
|
|
||||||
total := 0
|
total := 0
|
||||||
for _, line := range values {
|
for _, line := range values {
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func countTrees(input []string, right, down int) int {
|
func countTrees(input []string, right, down int) int {
|
||||||
|
@ -26,7 +26,7 @@ func countTrees(input []string, right, down int) int {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
|
|
||||||
switch step {
|
switch step {
|
||||||
case "1":
|
case "1":
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -130,7 +129,7 @@ func makeInt(input string) int {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
values = util.SplitOnBlankLine(values)
|
values = util.SplitOnBlankLine(values)
|
||||||
|
|
||||||
fmt.Println("Valid Passports:", countValidPassports(values, step))
|
fmt.Println("Valid Passports:", countValidPassports(values, step))
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func calculateSeatNumber(input string) int {
|
func calculateSeatNumber(input string) int {
|
||||||
|
@ -28,7 +28,7 @@ func calculateSeatNumber(input string) int {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
|
|
||||||
switch step {
|
switch step {
|
||||||
case "1":
|
case "1":
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -45,7 +44,7 @@ func countAnswerIntersection(input string) int {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
groups := util.SplitOnBlankLine(values)
|
groups := util.SplitOnBlankLine(values)
|
||||||
|
|
||||||
total := 0
|
total := 0
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Node struct {
|
type Node struct {
|
||||||
|
@ -89,7 +89,7 @@ func countChildren(node *Node) int {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
|
|
||||||
nodeMap = make(map[string]*Node)
|
nodeMap = make(map[string]*Node)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Instruction struct {
|
type Instruction struct {
|
||||||
|
@ -59,7 +59,7 @@ func executeProgram(instructions []Instruction) (int, bool) {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
|
|
||||||
instructions := make([]Instruction, 0)
|
instructions := make([]Instruction, 0)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SumTracker map[int][]Tuple
|
type SumTracker map[int][]Tuple
|
||||||
|
@ -85,7 +85,7 @@ func sumMinMax(values []int) int {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserInts(os.Args[2])
|
values := util.InputParserInts(os.Args[2])
|
||||||
|
|
||||||
var badValue int
|
var badValue int
|
||||||
sumMap := make(SumTracker)
|
sumMap := make(SumTracker)
|
||||||
|
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getMax(values map[int]bool) int {
|
func getMax(values map[int]bool) int {
|
||||||
|
@ -88,7 +88,7 @@ func countPaths(node *Node, target int) int {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserIntMap(os.Args[2])
|
values := util.InputParserIntMap(os.Args[2])
|
||||||
|
|
||||||
diffMap := make(map[int]int)
|
diffMap := make(map[int]int)
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func occupied1(board [][]byte, i, j int) int {
|
func occupied1(board [][]byte, i, j int) int {
|
||||||
|
@ -95,7 +95,7 @@ func countOccupied(board [][]byte) int {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
board := fileutils.InputParserBytes(os.Args[2])
|
board := util.InputParserBytes(os.Args[2])
|
||||||
|
|
||||||
changed := true
|
changed := true
|
||||||
for changed {
|
for changed {
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func distance(x1, y1, x2, y2 int) int {
|
func distance(x1, y1, x2, y2 int) int {
|
||||||
|
@ -133,7 +133,7 @@ func step2(values []string) (int, int) {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
|
|
||||||
x := 0
|
x := 0
|
||||||
y := 0
|
y := 0
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -108,7 +108,7 @@ func findTimestampWithCRT(busList []int) *big.Int {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
|
|
||||||
earliest, busList := parseInput(values)
|
earliest, busList := parseInput(values)
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Instruction struct {
|
type Instruction struct {
|
||||||
|
@ -140,7 +140,7 @@ func executeProgram2(program []Instruction) map[int64]int64 {
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
step := os.Args[1]
|
step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
|
|
||||||
var memory map[int64]int64
|
var memory map[int64]int64
|
||||||
program := parseProgram(values, step)
|
program := parseProgram(values, step)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package fileutils
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"git.annabunch.es/annabunches/adventofcode/2020/lib/fileutils"
|
"git.annabunch.es/annabunches/adventofcode/2020/lib/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// step := os.Args[1]
|
// step := os.Args[1]
|
||||||
values := fileutils.InputParserStrings(os.Args[2])
|
values := util.InputParserStrings(os.Args[2])
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user