Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ops.go 829B

1234567891011121314151617181920212223
  1. package intcode
  2. // OpcodeFunc is a function that describes an opcode implemented in the VM.
  3. type OpcodeFunc = func(vm *VirtualMachine, args []int)
  4. // AddOpcode takes the values from the memory addresses given by args 1 and 2, adds them together,
  5. // and stores at the memory address given by arg 3.
  6. func AddOpcode(vm *VirtualMachine, args []int) {
  7. vm.Memory[args[2]] = vm.Memory[args[0]] + vm.Memory[args[1]]
  8. vm.ip += 4
  9. }
  10. // MulOpcode takes the values from the memory addresses given by args 1 and 2, muliplies them together,
  11. // and stores at the memory address given by arg 3.
  12. func MulOpcode(vm *VirtualMachine, args []int) {
  13. vm.Memory[args[2]] = vm.Memory[args[0]] * vm.Memory[args[1]]
  14. vm.ip += 4
  15. }
  16. // HaltOpcode halts the VM and takes no arguments.
  17. func HaltOpcode(vm *VirtualMachine, args []int) {
  18. vm.Halted = true
  19. }