From dd5c07273014549897e68674f04dbc24be464f15 Mon Sep 17 00:00:00 2001 From: Parnic Date: Tue, 7 Jun 2022 09:54:40 -0500 Subject: [PATCH] Make opcode constants Just planning for the future... --- utilities/intcode.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/utilities/intcode.go b/utilities/intcode.go index abf1edc..84610ae 100644 --- a/utilities/intcode.go +++ b/utilities/intcode.go @@ -5,6 +5,12 @@ import ( "strings" ) +const ( + opAdd = 1 + opMul = 2 + opEnd = 99 +) + func ParseIntcodeProgram(programStr string) []int64 { nums := strings.Split(programStr, ",") program := make([]int64, len(nums)) @@ -23,7 +29,7 @@ func RunIntcodeProgram(program []int64) { for instructionPointer := 0; instructionPointer < len(program); { opcode := program[instructionPointer] switch opcode { - case 1: + case opAdd: param1 := program[instructionPointer+1] param2 := program[instructionPointer+2] param3 := program[instructionPointer+3] @@ -31,7 +37,7 @@ func RunIntcodeProgram(program []int64) { instructionPointer += 4 break - case 2: + case opMul: param1 := program[instructionPointer+1] param2 := program[instructionPointer+2] param3 := program[instructionPointer+3] @@ -39,7 +45,7 @@ func RunIntcodeProgram(program []int64) { instructionPointer += 4 break - case 99: + case opEnd: instructionPointer = len(program) break }