I kinda like this Run method on the receiver
This commit is contained in:
@ -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
|
||||||
|
@ -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 {
|
||||||
|
Reference in New Issue
Block a user