advent-of-code/2019/Scala/intcode/opcode/OpCode6.scala

22 lines
757 B
Scala
Raw Permalink Normal View History

2019-12-09 13:20:04 +01:00
package intcode.opcode
2019-12-09 22:21:05 +01:00
/**
* Jump-If-False
* If the first parameter is zero, it sets the instruction pointer to the value from the second parameter.
* Otherwise, it does nothing.
*
* checkConditionAndJump -> returns boolean for condition and int for pointer
*/
2019-12-09 13:20:04 +01:00
case object OpCode6 extends Jump
{
/** length of an instruction */
override val length: Int = 3
/** Executes instruction for given parameters and modes */
override def checkConditionAndJump(tape: Array[Long], relative: Long, param1: Long, param2: Long, param3: Long, mode1: Int, mode2: Int, mode3: Int): (Boolean, Int) =
{
if (accessor(relative, param1, mode1, tape) == 0) (true, accessor(relative, param2, mode2, tape).toInt)
else (false, 0)
}
}