More slight streamlining

This commit is contained in:
2022-06-07 10:01:29 -05:00
parent dd5c072730
commit 8cd4994300
3 changed files with 14 additions and 7 deletions

View File

@ -11,9 +11,11 @@ const (
opEnd = 99
)
func ParseIntcodeProgram(programStr string) []int64 {
type IntcodeProgram []int64
func ParseIntcodeProgram(programStr string) IntcodeProgram {
nums := strings.Split(programStr, ",")
program := make([]int64, len(nums))
program := make(IntcodeProgram, len(nums))
for idx, num := range nums {
iNum, err := strconv.ParseInt(num, 10, 64)
if err != nil {
@ -25,7 +27,7 @@ func ParseIntcodeProgram(programStr string) []int64 {
return program
}
func RunIntcodeProgram(program []int64) {
func RunIntcodeProgram(program IntcodeProgram) {
for instructionPointer := 0; instructionPointer < len(program); {
opcode := program[instructionPointer]
switch opcode {

View File

@ -24,6 +24,11 @@ func getData(filename string, lineHandler func(line string)) {
}
}
func LoadIntcodeProgram(filename string) IntcodeProgram {
programStr := GetStringContents(filename)
return ParseIntcodeProgram(programStr)
}
func GetStringContents(filename string) string {
var retval string
getData(filename, func(line string) {