runner

package
Version: v0.0.0-...-627063f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2020 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(input string) (string, error)

Run takes an instruction-set and uses it to generate a surface and guide a set a robots along its surface.

Lines for the instruction-set must be delimited by '\n' and contain at least three lines in the following format:

5 5 <-- Line 0: This constructs a 2D surface.

1 1 N <-- Line 1: This constructs and places a robot on the surface.

LMLLMLM <-- Line 2: This moves the robot along the surface.

The input can repeat the instructions outlined on line 1 and 2 in order to place more robots on the surface, for example:

5 5

1 1 N

LMLMLM

2 2 S

LLLLLL

Run will return the results of robots final resting positions in the following format:

2 2 E

1 1 N

Note that output is delimited by '\n' and the number of lines is equal to the number of robots constructed.

If an error occurs, Run will return the resting places of ALL robots that have successfully moved across the surface AND the error, for example:

5 5

1 1 N

L

1 1 N

MMMMMMM

Will return a string "1 1 W" and an out-of-bounds error.

Types

type EvenInputLinesError

type EvenInputLinesError struct{ Lines int }

EvenInputLinesError is an error that is used whenever the input to the Run command has an even number of instructions. You can never have an even number of commands since a surface needs one line of instructions, while a robot requires two. This can be reduced to the rule 2n + 1, which is also the rule for an odd number.

func (*EvenInputLinesError) Error

func (e *EvenInputLinesError) Error() string

Error outputs a message relating to the even number of instructions within the input.

type MissingInputLinesError

type MissingInputLinesError struct{ Lines int }

MissingInputLinesError is an error that is used whenever the number of instructions given to the Run command is less than the expected amount.

func (*MissingInputLinesError) Error

func (m *MissingInputLinesError) Error() string

Error outputs a message relating to the missing input.

type ParseRobotCoordinateError

type ParseRobotCoordinateError struct {
	ID         int
	Coordinate string
	Position   string
	Err        error
}

ParseRobotCoordinateError is an error that is thrown whenever a coordinate used for a robot from a instruction-set is incorrect.

func (*ParseRobotCoordinateError) Error

func (s *ParseRobotCoordinateError) Error() string

Error outputs a message that relates to the coordinate that is unable to be parsed.

func (*ParseRobotCoordinateError) Unwrap

func (s *ParseRobotCoordinateError) Unwrap() error

Unwrap returns the error that is contained within ParseRobotCoordinateError

type ParseRobotDirectionError

type ParseRobotDirectionError struct {
	Direction string
	ID        int
	Err       error
}

ParseRobotDirectionError is an error that is thrown whenever a direction used for a robot is unable to be parsed.

func (*ParseRobotDirectionError) Error

func (p *ParseRobotDirectionError) Error() string

Error outputs a message that relates to the direction that is unable to be parsed.

func (*ParseRobotDirectionError) Unwrap

func (p *ParseRobotDirectionError) Unwrap() error

Unwrap returns the error contained within ParseRobotDirectionError.

type ParseRobotMovementError

type ParseRobotMovementError struct {
	Movement string
	ID       int
	Err      error
}

ParseRobotMovementError is an error that is returned whenever a movement instruction is unable to be parsed.

func (*ParseRobotMovementError) Error

func (p *ParseRobotMovementError) Error() string

Error outputs a message relating to the movement that is unable to be parsed.

func (*ParseRobotMovementError) Unwrap

func (p *ParseRobotMovementError) Unwrap() error

Unwrap returns the error that is contained within the ParseRobotMovementError.

type ParseSurfaceBoundaryError

type ParseSurfaceBoundaryError struct {
	Coordinate string
	Bounary    string
	Err        error
}

ParseSurfaceBoundaryError is an error that is used whenever a coordinate for a surface cannot be parsed into an int.

func (*ParseSurfaceBoundaryError) Error

func (s *ParseSurfaceBoundaryError) Error() string

Error outputs a message about the coordinate that was unable to be parsed.

func (*ParseSurfaceBoundaryError) Unwrap

func (s *ParseSurfaceBoundaryError) Unwrap() error

Unwrap returns the error that is contained within the ParseSurfaceBoundaryError.

type RobotInstructionLengthError

type RobotInstructionLengthError struct {
	Instructions string
	ID           int
}

RobotInstructionLengthError is an error that is thrown whenever the number of instructions used to construct a robot is not equal to runner.robotInstructionLength

func (*RobotInstructionLengthError) Error

Error returns a message around the unexpected instruction length.

type RobotOutOfBoundsError

type RobotOutOfBoundsError struct {
	ID int
	X  int
	Y  int
}

RobotOutOfBoundsError is an error that is returned whenever a robot moves out of bounds within a surface.

func (*RobotOutOfBoundsError) Error

func (r *RobotOutOfBoundsError) Error() string

Error outputs a message that relates to the out-of-bound position.

type SurfaceDimensionError

type SurfaceDimensionError struct {
	Dimensions int
	Surface    string
}

SurfaceDimensionError is an error that is thrown whenever a surface does not have two dimensions. I.E the instruction-set 2 2 3 is incorrect since that would relate to a three-dimensional coordinate.

func (*SurfaceDimensionError) Error

func (s *SurfaceDimensionError) Error() string

Error outputs a message relating to an incorrect number of dimensions for a surface.

type SurfaceError

type SurfaceError struct {
	Err error
}

SurfaceError is an error that is returned whenever a surface is unable to be constructed. It wraps any error returned from plateau.New.

func (*SurfaceError) Error

func (s *SurfaceError) Error() string

Error outputs a simple message stating the surface could not be created.

func (*SurfaceError) Unwrap

func (s *SurfaceError) Unwrap() error

Unwrap returns the error that is contained within SurfaceError.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL