2
\$\begingroup\$

(This is not a duplicate of Follow the path, as this challenge have invalid path detection and use ><^v in the output.)

Task

So your task is to take in the description of the path and draw it out in a "Befunge(or a lot of other 2D esolangs)-like" format, and detect if it is invalid. Note that if the path is invalid, you shall not output anything except a printable custom character which cannot be one of ><^v or space.

  • The path would be invalid if the path is crossed.

  • Or, if you moved off the top or left edge.

You begins at the top-left corner.

  • >n moves you right n characters. Your trail is >.

  • ^n moves you up n characters. Your trail is ^.

  • <n moves you left n characters. Your trail is <.

  • vn moves you down n characters. Your trail is v.

Test Cases

Input: >3v3

Output:
>>>v
   v
   v

Input: v4>1^2>3

Output:
v
v
v>>>
v^
>^

Input: >5<3

Output:
!

(Or any character you want, except ><^v and space.)

Input: [NONE]

Output: [NONE]

Input: >4v2<2^2

Output:
>>>>v
  ^ v
  ^<<

Input: >4v2<2^3

Output:
!

(Or any character you want, except ><^v and space.)

Input:
>3v3<6

Output:
!

(Or any character you want, except ><^v and space.)

Rules

  • Standard loopholes are forbidden.

  • Least bytes wins.

  • This was written in a hurry.

\$\endgroup\$
  • \$\begingroup\$ @JonathanAllan Well, >4v2<2^3 crosses itself and is thus... invalid, so I outputted a ! (or custom character). I didn't get what you mean? \$\endgroup\$ – HighlyRadioactive Dec 21 '19 at 13:46
  • \$\begingroup\$ Just noticed I read above rather than below, sorry! \$\endgroup\$ – Jonathan Allan Dec 21 '19 at 13:47
  • \$\begingroup\$ Can we input an array/list of (direction, number) tuples/arrays/lists? \$\endgroup\$ – my pronoun is monicareinstate Dec 21 '19 at 14:06
  • \$\begingroup\$ @mypronounismonicareinstate Yes. \$\endgroup\$ – HighlyRadioactive Dec 21 '19 at 14:07
  • 2
    \$\begingroup\$ @HighlyRadioactive I'm pretty sure requiring different IO, removing the last-character-must-be-X requirement and requiring input validation doesn't make this less of a duplicate, as the only reason the answers can't ported from that question trivially is the input validation requirement, and that is boring \$\endgroup\$ – my pronoun is monicareinstate Dec 21 '19 at 14:20
1
\$\begingroup\$

Charcoal, 46 bytes

≔⁰ηF⪪S²FI§ι¹«≧⁺℅KKη✳⊗⌕>^<§ι⁰§ι⁰≧⁺∨‹ⅈ⁰‹ⅉ⁰η¿η«⎚!

Try it online! Link is to verbose version of code. Explanation:

≔⁰η

Assume everything is OK.

F⪪S²

Loop over the instructions.

FI§ι¹«

Loop over the number of steps.

≧⁺℅KKη

Check whether the path has crossed.

✳⊗⌕>^<§ι⁰§ι⁰

Output each character in the appropriate direction.

≧⁺∨‹ⅈ⁰‹ⅉ⁰η

Check whether the path has moved off the top or left edge.

¿η«⎚!

If something went wrong, replace the output with a !.

\$\endgroup\$
  • \$\begingroup\$ I like how you make use of the feature that you can "clean" the output. Neat! \$\endgroup\$ – HighlyRadioactive Dec 21 '19 at 12:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.