Use 'helpers' module for previous days

This commit is contained in:
2019-12-05 09:01:52 -06:00
parent 5edde5ba62
commit d5fb449c31
4 changed files with 16 additions and 92 deletions

View File

@@ -1,19 +1,16 @@
package main
import (
"bufio"
"fmt"
"log"
helpers "git.bullercodeworks.com/brian/adventofcode/helpers"
"math"
"os"
"strconv"
"strings"
)
const MaxInt = int(^uint(0) >> 1)
func main() {
inp := StdinToStringSlice()
inp := helpers.StdinToStringSlice()
part1(inp)
}
@@ -69,7 +66,7 @@ func NewWire() *Wire {
func (w *Wire) Go(cmd string) {
dir := cmd[0]
length := Atoi(cmd[1:])
length := helpers.Atoi(cmd[1:])
for length > 0 {
w.Move(dir)
w.path = append(w.path, w.curr)
@@ -105,21 +102,3 @@ func (c Coord) string() string {
func manhattanDistance(x1, y1, x2, y2 int) int {
return int(math.Abs(float64(x1)-float64(x2)) + math.Abs(float64(y1)-float64(y2)))
}
func StdinToStringSlice() []string {
var input []string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
input = append(input, scanner.Text())
}
return input
}
func Atoi(i string) int {
var ret int
var err error
if ret, err = strconv.Atoi(i); err != nil {
log.Fatal("Invalid Atoi")
}
return ret
}