Day 14 & 15 progress

This commit is contained in:
2019-12-15 08:57:44 -06:00
parent 74510f9723
commit a3cee63862
9 changed files with 336 additions and 2 deletions

View File

@@ -3,7 +3,11 @@ package intcodeprocessor
import (
"errors"
"fmt"
helpers "git.bullercodeworks.com/brian/adventofcode/helpers"
"io/ioutil"
"math"
"os"
"strings"
)
const (
@@ -48,6 +52,20 @@ type Program struct {
debug bool
}
func ReadIntCodeFile(fn string) []int {
dat, err := ioutil.ReadFile(fn)
if err != nil {
fmt.Println("Error reading program file:", err.Error())
os.Exit(1)
}
var prog []int
stringDat := strings.TrimSpace(string(dat))
for _, v := range strings.Split(stringDat, ",") {
prog = append(prog, helpers.Atoi(v))
}
return prog
}
func NewProgram(prog []int) *Program {
p := new(Program)
p.originalCode = make([]int, len(prog))