A higher resolution is required to access the IDE
- 18
Learning Opportunities
This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.
Statement
Goal
A robot is navigating a 2D plane, following a set of movement instructions.The following symbols are used to indicate the movement directions:
Each instruction consists of a direction and an integer step indicating the number of units to move in that direction. For example, "
After executing all instructions, the robot returns to its starting point, creating a closed, non-self-intersecting polygon.
Example:
4
> 3
v 2
< 3
^ 2
The robot will make a path looks like:
...... .####. .#..#. .####. ......
We want to know the area enclosed by the robot's path, including the path.
It looks like:
...... .####. .####. .####. ......
So, the area is 12.
Can you determine the enclosed area based on the given set of instructions?
Input
line 1: number of instructions n
following n lines: one instruction in each row. formatted as direction step, meaning that the robot should move step units in direction
following n lines: one instruction in each row. formatted as direction step, meaning that the robot should move step units in direction
Output
line 1: area inside the path, including the path.
Constraints
Example
Input
4 < 6 ^ 4 > 6 v 4
Output
35
A higher resolution is required to access the IDE