I kinda like this Run method on the receiver

This commit is contained in:
2022-06-07 22:54:57 -05:00
parent 092fe15b07
commit 2a8384949f
2 changed files with 3 additions and 3 deletions

View File

@ -28,7 +28,7 @@ func (d *Day02) getProgramWithParams(param1, param2 int64) utilities.IntcodeProg
func (d *Day02) Part1() string { func (d *Day02) Part1() string {
program := d.getProgramWithParams(12, 2) program := d.getProgramWithParams(12, 2)
utilities.RunIntcodeProgram(program) program.Run()
return fmt.Sprintf("Position 0 = %s%d%s", utilities.TextBold, program[0], utilities.TextReset) return fmt.Sprintf("Position 0 = %s%d%s", utilities.TextBold, program[0], utilities.TextReset)
} }
@ -42,7 +42,7 @@ func (d *Day02) Part2() string {
for noun = 0; noun <= 99; noun++ { for noun = 0; noun <= 99; noun++ {
for verb = 0; verb <= 99; verb++ { for verb = 0; verb <= 99; verb++ {
program := d.getProgramWithParams(noun, verb) program := d.getProgramWithParams(noun, verb)
utilities.RunIntcodeProgram(program) program.Run()
if program[0] == sentinel { if program[0] == sentinel {
found = true found = true

View File

@ -27,7 +27,7 @@ func ParseIntcodeProgram(programStr string) IntcodeProgram {
return program return program
} }
func RunIntcodeProgram(program IntcodeProgram) { func (program IntcodeProgram) Run() {
for instructionPointer := 0; instructionPointer < len(program); { for instructionPointer := 0; instructionPointer < len(program); {
opcode := program[instructionPointer] opcode := program[instructionPointer]
switch opcode { switch opcode {