Use 'helpers' module for previous days

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

View File

@ -1,23 +1,21 @@
package main
import (
"bufio"
"fmt"
"log"
"math"
"os"
"strconv"
helpers "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := StdinToStringSlice()
inp := helpers.StdinToStringSlice()
fmt.Println("Fuel Required:", part1(inp))
}
func part1(inp []string) int {
var total int
for _, v := range inp {
total = total + part2(fuelRequired(float64(Atoi(v))))
total = total + part2(fuelRequired(float64(helpers.Atoi(v))))
}
return total
}
@ -39,21 +37,3 @@ func fuelRequired(mass float64) int {
}
return int(res) - 2
}
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
}

View File

@ -1,20 +1,19 @@
package main
import (
"bufio"
"fmt"
intcode "git.bullercodeworks.com/brian/adventofcode/2019/intcode-processor"
"log"
"os"
"strconv"
"strings"
intcode "git.bullercodeworks.com/brian/adventofcode/2019/intcode-processor"
helpers "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := StdinToString()
inp := helpers.StdinToString()
var prog []int
for _, v := range strings.Split(inp, ",") {
prog = append(prog, Atoi(v))
prog = append(prog, helpers.Atoi(v))
}
part1(prog)
part2(prog)
@ -129,21 +128,3 @@ func add(i, j int, prog []int) int {
func mult(i, j int, prog []int) int {
return prog[i] * prog[j]
}
func StdinToString() string {
var input string
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
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
}

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
}

View File

@ -1,9 +1,11 @@
package main
import "fmt"
import (
helpers "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := StdinToStringSlice()
inp := helpers.StdinToStringSlice()
part1(inp)
part2(inp)
}
@ -13,21 +15,3 @@ func part1(inp []string) {
func part2(inp []string) {
}
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
}