Track an object in 2d space

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
6
down vote

favorite












Description



The task of this challenge is to devise a program or function that tracks a given object in an $n×n$ space.



I/O



Your program will be given 3 inputs, which may be taken in any sensible way:



n will be the size of the plane's side. (so, for $n=5$, your plane will be $5×5$). You may assume n will always be an odd integer.



s will be the starting position of the object, given as a pair of $(x, y)$ coordinates.



D will be a vector of ordered pairs. D will follow the format $D = [(d_0,t_0),(d_1,t_1),...,(d_n,t_n)]$, where $d_k$ will always be one of 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', for the cardinal and primary intercardinal directions, and $t_k$ will be an integer for the number of 'ticks'.



Given these inputs, your program must output a tracking of the object in the plane.



Rules



The output must contain the plane's boundaries. E.g.:




- 21012 +
+┌─────┐
2│ │
1│ │
0│ │
1│ │
2│ │
-└─────┘


would be an example of an empty $5×5$ plane. The numbers above and to the side are for reference only and don't need to be printed.



You may use whatever character(s) for the boundaries, as long as it's not whitespace (or renders as whitespace). The characters you choose must delineate the full plane, meaning that there can be no gaps between them.




Some acceptable planes include:

┌──┐ .... ---- +--+
│ │ . . | | | |
│ │ . . | | | |
└──┘; ....; ----; +--+

Nonacceptable planes include:

.... .... ++++ . .
. . + + . .
. + + . .
; ....; ....; + +; . .


The object to be tracked may be whatever character you choose, as long as it only occupies 1 space on the plane and is different from the boundary characters.



The trace of the tracked object may also be whatever characters you choose, as long as they only occupy 1 space on the plane and are different from the object.



For each element $(d_k,t_k)$ in $D$, the object must move $t$ spaces towards $d$, and leave a trace behind.



If the object would hit a boundary, it'll be reflected. If the object still has any moves left, it'll keep moving in the direction it was reflected to.



For reference, these directions reflect to each other:



$Nrightleftharpoons S$ → when the top or bottom boundary is met;



$Erightleftharpoons W$ → when a lateral boundary is met;



The final output will contain the newest possible traces, that is, if the object would leave a trace in a space where there's already a trace, the newer trace character will overwrite the older.



As usual, standard loopholes are forbidden by default.



Scoring:



This is a code-golf challenge.



Examples:



Input: $n=5$, $s=(0,0)$, $D=[('NW',2),('S',2),('E',1)]$



Working it out:



$t=0$




0
┌─────┐
│ │
│ │
0│ ○ │
│ │
│ │
└─────┘


$t=2$




0
┌─────┐
│○ │
│ │
0│ │
│ │
│ │
└─────┘


$t=4$




0
┌─────┐
│∧ │
│| │
0│○ │
│ │
│ │
└─────┘


$t=5$, which will be the output.




0
┌─────┐
│∧ │
│| │
0│└○ │
│ │
│ │
└─────┘


(The 0s are just for reference, and they don't need to be in the final output.)




Input: $n=9$, $s=(3,-1)$, $D=[('N',2),('SW',8),('SE',3),('NE',8)]$



Notice that, when $t=10$:




0
┌─────────┐
│ │
│ │
│ │
│ ∧ │
0│ /| │
│ ○ / | │
│⟨ / │
│ / │
│ ∨ │
└─────────┘


The object has been reflected twice: once when reaching the bottom of the plane while going towards the $SW$, where it reflects to the $NW$; then once again when reaching the left side of the plane, where $NW$ reflects to $NE$.



The final output comes at $t=21$:




0
┌─────────┐
│ ○ │
│ │
│ │
│ │
0│ /|⟩│
│ ∧ / / │
│⟨ / / │
│ / │
│ ∨ ∨ │
└─────────┘


Test cases:



Input: $n=5$, $s=(0,0)$, $D=[('NW',2),('S',2),('E',1)]$



Output:




0
┌─────┐
│∧ │
│| │
0│└○ │
│ │
│ │
└─────┘





Input: $n=9$, $s=(3,-1)$, $D=[('N',2),('SW',8),('SE',3),('NE',8)]$

Output:




0
┌─────────┐
│ ○ │
│ │
│ │
│ │
0│ /|⟩│
│ ∧ / / │
│⟨ / / │
│ / │
│ ∨ ∨ │
└─────────┘





Input: $n=3$, $s=(1,1)$, $D=[('N',5),('W',5)]$

Output:




0
┌───┐
│ |│
0│-○┐│
│ |│
└───┘





Input: $n=11$, $s=(3,-5)$, $D=[('NW',8),('E',5),('SE',3),('SW',5),('N',6),('NE',10)]$

Output:




0
┌───────────┐
│ ∧ │
│ / │
│┌---/ │
│ / │
│ / ⟩│
0│ | / / │
│ | / ○ │
│ | / │
│ | / │
│ |/ │
│ ∨ │
└───────────┘









share|improve this question



















  • 1




    @Arnauld I see your point. Since no answers have been posted yet, I’ll edit the question to reflect like your example A rather than B, since it does make more sense in the context of the question.
    – J. Sallé
    2 hours ago










  • Forgot to mention that this challenge was sandboxed.
    – J. Sallé
    2 hours ago










  • Can we take 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW' as a 0-indexed (or 1-indexed) integer instead? So [('NW',2),('S',2),('E',1)] becomes [[7,2],[4,2],[2,1]] for example.
    – Kevin Cruijssen
    2 hours ago











  • @KevinCruijssen sure, no problem. Just make sure to point that out in the answer.
    – J. Sallé
    2 hours ago






  • 1




    @Arnauld yes, you're allowed to use a single trace character. I used more than one so it'd be easier to visualize the test cases, but it's not required. Just make sure the trace character is different from the character of the object being traced.
    – J. Sallé
    2 hours ago














up vote
6
down vote

favorite












Description



The task of this challenge is to devise a program or function that tracks a given object in an $n×n$ space.



I/O



Your program will be given 3 inputs, which may be taken in any sensible way:



n will be the size of the plane's side. (so, for $n=5$, your plane will be $5×5$). You may assume n will always be an odd integer.



s will be the starting position of the object, given as a pair of $(x, y)$ coordinates.



D will be a vector of ordered pairs. D will follow the format $D = [(d_0,t_0),(d_1,t_1),...,(d_n,t_n)]$, where $d_k$ will always be one of 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', for the cardinal and primary intercardinal directions, and $t_k$ will be an integer for the number of 'ticks'.



Given these inputs, your program must output a tracking of the object in the plane.



Rules



The output must contain the plane's boundaries. E.g.:




- 21012 +
+┌─────┐
2│ │
1│ │
0│ │
1│ │
2│ │
-└─────┘


would be an example of an empty $5×5$ plane. The numbers above and to the side are for reference only and don't need to be printed.



You may use whatever character(s) for the boundaries, as long as it's not whitespace (or renders as whitespace). The characters you choose must delineate the full plane, meaning that there can be no gaps between them.




Some acceptable planes include:

┌──┐ .... ---- +--+
│ │ . . | | | |
│ │ . . | | | |
└──┘; ....; ----; +--+

Nonacceptable planes include:

.... .... ++++ . .
. . + + . .
. + + . .
; ....; ....; + +; . .


The object to be tracked may be whatever character you choose, as long as it only occupies 1 space on the plane and is different from the boundary characters.



The trace of the tracked object may also be whatever characters you choose, as long as they only occupy 1 space on the plane and are different from the object.



For each element $(d_k,t_k)$ in $D$, the object must move $t$ spaces towards $d$, and leave a trace behind.



If the object would hit a boundary, it'll be reflected. If the object still has any moves left, it'll keep moving in the direction it was reflected to.



For reference, these directions reflect to each other:



$Nrightleftharpoons S$ → when the top or bottom boundary is met;



$Erightleftharpoons W$ → when a lateral boundary is met;



The final output will contain the newest possible traces, that is, if the object would leave a trace in a space where there's already a trace, the newer trace character will overwrite the older.



As usual, standard loopholes are forbidden by default.



Scoring:



This is a code-golf challenge.



Examples:



Input: $n=5$, $s=(0,0)$, $D=[('NW',2),('S',2),('E',1)]$



Working it out:



$t=0$




0
┌─────┐
│ │
│ │
0│ ○ │
│ │
│ │
└─────┘


$t=2$




0
┌─────┐
│○ │
│ │
0│ │
│ │
│ │
└─────┘


$t=4$




0
┌─────┐
│∧ │
│| │
0│○ │
│ │
│ │
└─────┘


$t=5$, which will be the output.




0
┌─────┐
│∧ │
│| │
0│└○ │
│ │
│ │
└─────┘


(The 0s are just for reference, and they don't need to be in the final output.)




Input: $n=9$, $s=(3,-1)$, $D=[('N',2),('SW',8),('SE',3),('NE',8)]$



Notice that, when $t=10$:




0
┌─────────┐
│ │
│ │
│ │
│ ∧ │
0│ /| │
│ ○ / | │
│⟨ / │
│ / │
│ ∨ │
└─────────┘


The object has been reflected twice: once when reaching the bottom of the plane while going towards the $SW$, where it reflects to the $NW$; then once again when reaching the left side of the plane, where $NW$ reflects to $NE$.



The final output comes at $t=21$:




0
┌─────────┐
│ ○ │
│ │
│ │
│ │
0│ /|⟩│
│ ∧ / / │
│⟨ / / │
│ / │
│ ∨ ∨ │
└─────────┘


Test cases:



Input: $n=5$, $s=(0,0)$, $D=[('NW',2),('S',2),('E',1)]$



Output:




0
┌─────┐
│∧ │
│| │
0│└○ │
│ │
│ │
└─────┘





Input: $n=9$, $s=(3,-1)$, $D=[('N',2),('SW',8),('SE',3),('NE',8)]$

Output:




0
┌─────────┐
│ ○ │
│ │
│ │
│ │
0│ /|⟩│
│ ∧ / / │
│⟨ / / │
│ / │
│ ∨ ∨ │
└─────────┘





Input: $n=3$, $s=(1,1)$, $D=[('N',5),('W',5)]$

Output:




0
┌───┐
│ |│
0│-○┐│
│ |│
└───┘





Input: $n=11$, $s=(3,-5)$, $D=[('NW',8),('E',5),('SE',3),('SW',5),('N',6),('NE',10)]$

Output:




0
┌───────────┐
│ ∧ │
│ / │
│┌---/ │
│ / │
│ / ⟩│
0│ | / / │
│ | / ○ │
│ | / │
│ | / │
│ |/ │
│ ∨ │
└───────────┘









share|improve this question



















  • 1




    @Arnauld I see your point. Since no answers have been posted yet, I’ll edit the question to reflect like your example A rather than B, since it does make more sense in the context of the question.
    – J. Sallé
    2 hours ago










  • Forgot to mention that this challenge was sandboxed.
    – J. Sallé
    2 hours ago










  • Can we take 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW' as a 0-indexed (or 1-indexed) integer instead? So [('NW',2),('S',2),('E',1)] becomes [[7,2],[4,2],[2,1]] for example.
    – Kevin Cruijssen
    2 hours ago











  • @KevinCruijssen sure, no problem. Just make sure to point that out in the answer.
    – J. Sallé
    2 hours ago






  • 1




    @Arnauld yes, you're allowed to use a single trace character. I used more than one so it'd be easier to visualize the test cases, but it's not required. Just make sure the trace character is different from the character of the object being traced.
    – J. Sallé
    2 hours ago












up vote
6
down vote

favorite









up vote
6
down vote

favorite











Description



The task of this challenge is to devise a program or function that tracks a given object in an $n×n$ space.



I/O



Your program will be given 3 inputs, which may be taken in any sensible way:



n will be the size of the plane's side. (so, for $n=5$, your plane will be $5×5$). You may assume n will always be an odd integer.



s will be the starting position of the object, given as a pair of $(x, y)$ coordinates.



D will be a vector of ordered pairs. D will follow the format $D = [(d_0,t_0),(d_1,t_1),...,(d_n,t_n)]$, where $d_k$ will always be one of 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', for the cardinal and primary intercardinal directions, and $t_k$ will be an integer for the number of 'ticks'.



Given these inputs, your program must output a tracking of the object in the plane.



Rules



The output must contain the plane's boundaries. E.g.:




- 21012 +
+┌─────┐
2│ │
1│ │
0│ │
1│ │
2│ │
-└─────┘


would be an example of an empty $5×5$ plane. The numbers above and to the side are for reference only and don't need to be printed.



You may use whatever character(s) for the boundaries, as long as it's not whitespace (or renders as whitespace). The characters you choose must delineate the full plane, meaning that there can be no gaps between them.




Some acceptable planes include:

┌──┐ .... ---- +--+
│ │ . . | | | |
│ │ . . | | | |
└──┘; ....; ----; +--+

Nonacceptable planes include:

.... .... ++++ . .
. . + + . .
. + + . .
; ....; ....; + +; . .


The object to be tracked may be whatever character you choose, as long as it only occupies 1 space on the plane and is different from the boundary characters.



The trace of the tracked object may also be whatever characters you choose, as long as they only occupy 1 space on the plane and are different from the object.



For each element $(d_k,t_k)$ in $D$, the object must move $t$ spaces towards $d$, and leave a trace behind.



If the object would hit a boundary, it'll be reflected. If the object still has any moves left, it'll keep moving in the direction it was reflected to.



For reference, these directions reflect to each other:



$Nrightleftharpoons S$ → when the top or bottom boundary is met;



$Erightleftharpoons W$ → when a lateral boundary is met;



The final output will contain the newest possible traces, that is, if the object would leave a trace in a space where there's already a trace, the newer trace character will overwrite the older.



As usual, standard loopholes are forbidden by default.



Scoring:



This is a code-golf challenge.



Examples:



Input: $n=5$, $s=(0,0)$, $D=[('NW',2),('S',2),('E',1)]$



Working it out:



$t=0$




0
┌─────┐
│ │
│ │
0│ ○ │
│ │
│ │
└─────┘


$t=2$




0
┌─────┐
│○ │
│ │
0│ │
│ │
│ │
└─────┘


$t=4$




0
┌─────┐
│∧ │
│| │
0│○ │
│ │
│ │
└─────┘


$t=5$, which will be the output.




0
┌─────┐
│∧ │
│| │
0│└○ │
│ │
│ │
└─────┘


(The 0s are just for reference, and they don't need to be in the final output.)




Input: $n=9$, $s=(3,-1)$, $D=[('N',2),('SW',8),('SE',3),('NE',8)]$



Notice that, when $t=10$:




0
┌─────────┐
│ │
│ │
│ │
│ ∧ │
0│ /| │
│ ○ / | │
│⟨ / │
│ / │
│ ∨ │
└─────────┘


The object has been reflected twice: once when reaching the bottom of the plane while going towards the $SW$, where it reflects to the $NW$; then once again when reaching the left side of the plane, where $NW$ reflects to $NE$.



The final output comes at $t=21$:




0
┌─────────┐
│ ○ │
│ │
│ │
│ │
0│ /|⟩│
│ ∧ / / │
│⟨ / / │
│ / │
│ ∨ ∨ │
└─────────┘


Test cases:



Input: $n=5$, $s=(0,0)$, $D=[('NW',2),('S',2),('E',1)]$



Output:




0
┌─────┐
│∧ │
│| │
0│└○ │
│ │
│ │
└─────┘





Input: $n=9$, $s=(3,-1)$, $D=[('N',2),('SW',8),('SE',3),('NE',8)]$

Output:




0
┌─────────┐
│ ○ │
│ │
│ │
│ │
0│ /|⟩│
│ ∧ / / │
│⟨ / / │
│ / │
│ ∨ ∨ │
└─────────┘





Input: $n=3$, $s=(1,1)$, $D=[('N',5),('W',5)]$

Output:




0
┌───┐
│ |│
0│-○┐│
│ |│
└───┘





Input: $n=11$, $s=(3,-5)$, $D=[('NW',8),('E',5),('SE',3),('SW',5),('N',6),('NE',10)]$

Output:




0
┌───────────┐
│ ∧ │
│ / │
│┌---/ │
│ / │
│ / ⟩│
0│ | / / │
│ | / ○ │
│ | / │
│ | / │
│ |/ │
│ ∨ │
└───────────┘









share|improve this question















Description



The task of this challenge is to devise a program or function that tracks a given object in an $n×n$ space.



I/O



Your program will be given 3 inputs, which may be taken in any sensible way:



n will be the size of the plane's side. (so, for $n=5$, your plane will be $5×5$). You may assume n will always be an odd integer.



s will be the starting position of the object, given as a pair of $(x, y)$ coordinates.



D will be a vector of ordered pairs. D will follow the format $D = [(d_0,t_0),(d_1,t_1),...,(d_n,t_n)]$, where $d_k$ will always be one of 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW', for the cardinal and primary intercardinal directions, and $t_k$ will be an integer for the number of 'ticks'.



Given these inputs, your program must output a tracking of the object in the plane.



Rules



The output must contain the plane's boundaries. E.g.:




- 21012 +
+┌─────┐
2│ │
1│ │
0│ │
1│ │
2│ │
-└─────┘


would be an example of an empty $5×5$ plane. The numbers above and to the side are for reference only and don't need to be printed.



You may use whatever character(s) for the boundaries, as long as it's not whitespace (or renders as whitespace). The characters you choose must delineate the full plane, meaning that there can be no gaps between them.




Some acceptable planes include:

┌──┐ .... ---- +--+
│ │ . . | | | |
│ │ . . | | | |
└──┘; ....; ----; +--+

Nonacceptable planes include:

.... .... ++++ . .
. . + + . .
. + + . .
; ....; ....; + +; . .


The object to be tracked may be whatever character you choose, as long as it only occupies 1 space on the plane and is different from the boundary characters.



The trace of the tracked object may also be whatever characters you choose, as long as they only occupy 1 space on the plane and are different from the object.



For each element $(d_k,t_k)$ in $D$, the object must move $t$ spaces towards $d$, and leave a trace behind.



If the object would hit a boundary, it'll be reflected. If the object still has any moves left, it'll keep moving in the direction it was reflected to.



For reference, these directions reflect to each other:



$Nrightleftharpoons S$ → when the top or bottom boundary is met;



$Erightleftharpoons W$ → when a lateral boundary is met;



The final output will contain the newest possible traces, that is, if the object would leave a trace in a space where there's already a trace, the newer trace character will overwrite the older.



As usual, standard loopholes are forbidden by default.



Scoring:



This is a code-golf challenge.



Examples:



Input: $n=5$, $s=(0,0)$, $D=[('NW',2),('S',2),('E',1)]$



Working it out:



$t=0$




0
┌─────┐
│ │
│ │
0│ ○ │
│ │
│ │
└─────┘


$t=2$




0
┌─────┐
│○ │
│ │
0│ │
│ │
│ │
└─────┘


$t=4$




0
┌─────┐
│∧ │
│| │
0│○ │
│ │
│ │
└─────┘


$t=5$, which will be the output.




0
┌─────┐
│∧ │
│| │
0│└○ │
│ │
│ │
└─────┘


(The 0s are just for reference, and they don't need to be in the final output.)




Input: $n=9$, $s=(3,-1)$, $D=[('N',2),('SW',8),('SE',3),('NE',8)]$



Notice that, when $t=10$:




0
┌─────────┐
│ │
│ │
│ │
│ ∧ │
0│ /| │
│ ○ / | │
│⟨ / │
│ / │
│ ∨ │
└─────────┘


The object has been reflected twice: once when reaching the bottom of the plane while going towards the $SW$, where it reflects to the $NW$; then once again when reaching the left side of the plane, where $NW$ reflects to $NE$.



The final output comes at $t=21$:




0
┌─────────┐
│ ○ │
│ │
│ │
│ │
0│ /|⟩│
│ ∧ / / │
│⟨ / / │
│ / │
│ ∨ ∨ │
└─────────┘


Test cases:



Input: $n=5$, $s=(0,0)$, $D=[('NW',2),('S',2),('E',1)]$



Output:




0
┌─────┐
│∧ │
│| │
0│└○ │
│ │
│ │
└─────┘





Input: $n=9$, $s=(3,-1)$, $D=[('N',2),('SW',8),('SE',3),('NE',8)]$

Output:




0
┌─────────┐
│ ○ │
│ │
│ │
│ │
0│ /|⟩│
│ ∧ / / │
│⟨ / / │
│ / │
│ ∨ ∨ │
└─────────┘





Input: $n=3$, $s=(1,1)$, $D=[('N',5),('W',5)]$

Output:




0
┌───┐
│ |│
0│-○┐│
│ |│
└───┘





Input: $n=11$, $s=(3,-5)$, $D=[('NW',8),('E',5),('SE',3),('SW',5),('N',6),('NE',10)]$

Output:




0
┌───────────┐
│ ∧ │
│ / │
│┌---/ │
│ / │
│ / ⟩│
0│ | / / │
│ | / ○ │
│ | / │
│ | / │
│ |/ │
│ ∨ │
└───────────┘






code-golf ascii-art






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 6 mins ago

























asked 3 hours ago









J. Sallé

1,528318




1,528318







  • 1




    @Arnauld I see your point. Since no answers have been posted yet, I’ll edit the question to reflect like your example A rather than B, since it does make more sense in the context of the question.
    – J. Sallé
    2 hours ago










  • Forgot to mention that this challenge was sandboxed.
    – J. Sallé
    2 hours ago










  • Can we take 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW' as a 0-indexed (or 1-indexed) integer instead? So [('NW',2),('S',2),('E',1)] becomes [[7,2],[4,2],[2,1]] for example.
    – Kevin Cruijssen
    2 hours ago











  • @KevinCruijssen sure, no problem. Just make sure to point that out in the answer.
    – J. Sallé
    2 hours ago






  • 1




    @Arnauld yes, you're allowed to use a single trace character. I used more than one so it'd be easier to visualize the test cases, but it's not required. Just make sure the trace character is different from the character of the object being traced.
    – J. Sallé
    2 hours ago












  • 1




    @Arnauld I see your point. Since no answers have been posted yet, I’ll edit the question to reflect like your example A rather than B, since it does make more sense in the context of the question.
    – J. Sallé
    2 hours ago










  • Forgot to mention that this challenge was sandboxed.
    – J. Sallé
    2 hours ago










  • Can we take 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW' as a 0-indexed (or 1-indexed) integer instead? So [('NW',2),('S',2),('E',1)] becomes [[7,2],[4,2],[2,1]] for example.
    – Kevin Cruijssen
    2 hours ago











  • @KevinCruijssen sure, no problem. Just make sure to point that out in the answer.
    – J. Sallé
    2 hours ago






  • 1




    @Arnauld yes, you're allowed to use a single trace character. I used more than one so it'd be easier to visualize the test cases, but it's not required. Just make sure the trace character is different from the character of the object being traced.
    – J. Sallé
    2 hours ago







1




1




@Arnauld I see your point. Since no answers have been posted yet, I’ll edit the question to reflect like your example A rather than B, since it does make more sense in the context of the question.
– J. Sallé
2 hours ago




@Arnauld I see your point. Since no answers have been posted yet, I’ll edit the question to reflect like your example A rather than B, since it does make more sense in the context of the question.
– J. Sallé
2 hours ago












Forgot to mention that this challenge was sandboxed.
– J. Sallé
2 hours ago




Forgot to mention that this challenge was sandboxed.
– J. Sallé
2 hours ago












Can we take 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW' as a 0-indexed (or 1-indexed) integer instead? So [('NW',2),('S',2),('E',1)] becomes [[7,2],[4,2],[2,1]] for example.
– Kevin Cruijssen
2 hours ago





Can we take 'N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW' as a 0-indexed (or 1-indexed) integer instead? So [('NW',2),('S',2),('E',1)] becomes [[7,2],[4,2],[2,1]] for example.
– Kevin Cruijssen
2 hours ago













@KevinCruijssen sure, no problem. Just make sure to point that out in the answer.
– J. Sallé
2 hours ago




@KevinCruijssen sure, no problem. Just make sure to point that out in the answer.
– J. Sallé
2 hours ago




1




1




@Arnauld yes, you're allowed to use a single trace character. I used more than one so it'd be easier to visualize the test cases, but it's not required. Just make sure the trace character is different from the character of the object being traced.
– J. Sallé
2 hours ago




@Arnauld yes, you're allowed to use a single trace character. I used more than one so it'd be easier to visualize the test cases, but it's not required. Just make sure the trace character is different from the character of the object being traced.
– J. Sallé
2 hours ago










1 Answer
1






active

oldest

votes

















up vote
3
down vote













JavaScript (ES6), 228 bytes



Takes input as (n,x,y,[[dir,len],[dir,len],...]) where directions are encoded counterclockwise from $0$ for South to $7$ for South-West.



Outputs a string with 0 for a boundary, 1 for a trace and 3 for the final position.





(n,x,y,a)=>(g=X=>Y>n?'':(Y%n&&X%n&&a.map(([d,l],i)=>(M=H=>(h-X|v-Y||(k|=a[i+!l]?1:3),l--&&M(H=(h+H)%n?H:-H,h+=H,v+=V=(v+V)%n?V:-V)))(~-(D='12221')[d],V=~-D[d+2&7]),h=x+n/2,v=n/2-y,k=' ')&&k)+(X<n?'':`
`)+g(X++<n?X:!++Y))(Y=!++n)


Try it online!






share|improve this answer






















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "200"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172837%2ftrack-an-object-in-2d-space%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote













    JavaScript (ES6), 228 bytes



    Takes input as (n,x,y,[[dir,len],[dir,len],...]) where directions are encoded counterclockwise from $0$ for South to $7$ for South-West.



    Outputs a string with 0 for a boundary, 1 for a trace and 3 for the final position.





    (n,x,y,a)=>(g=X=>Y>n?'':(Y%n&&X%n&&a.map(([d,l],i)=>(M=H=>(h-X|v-Y||(k|=a[i+!l]?1:3),l--&&M(H=(h+H)%n?H:-H,h+=H,v+=V=(v+V)%n?V:-V)))(~-(D='12221')[d],V=~-D[d+2&7]),h=x+n/2,v=n/2-y,k=' ')&&k)+(X<n?'':`
    `)+g(X++<n?X:!++Y))(Y=!++n)


    Try it online!






    share|improve this answer


























      up vote
      3
      down vote













      JavaScript (ES6), 228 bytes



      Takes input as (n,x,y,[[dir,len],[dir,len],...]) where directions are encoded counterclockwise from $0$ for South to $7$ for South-West.



      Outputs a string with 0 for a boundary, 1 for a trace and 3 for the final position.





      (n,x,y,a)=>(g=X=>Y>n?'':(Y%n&&X%n&&a.map(([d,l],i)=>(M=H=>(h-X|v-Y||(k|=a[i+!l]?1:3),l--&&M(H=(h+H)%n?H:-H,h+=H,v+=V=(v+V)%n?V:-V)))(~-(D='12221')[d],V=~-D[d+2&7]),h=x+n/2,v=n/2-y,k=' ')&&k)+(X<n?'':`
      `)+g(X++<n?X:!++Y))(Y=!++n)


      Try it online!






      share|improve this answer
























        up vote
        3
        down vote










        up vote
        3
        down vote









        JavaScript (ES6), 228 bytes



        Takes input as (n,x,y,[[dir,len],[dir,len],...]) where directions are encoded counterclockwise from $0$ for South to $7$ for South-West.



        Outputs a string with 0 for a boundary, 1 for a trace and 3 for the final position.





        (n,x,y,a)=>(g=X=>Y>n?'':(Y%n&&X%n&&a.map(([d,l],i)=>(M=H=>(h-X|v-Y||(k|=a[i+!l]?1:3),l--&&M(H=(h+H)%n?H:-H,h+=H,v+=V=(v+V)%n?V:-V)))(~-(D='12221')[d],V=~-D[d+2&7]),h=x+n/2,v=n/2-y,k=' ')&&k)+(X<n?'':`
        `)+g(X++<n?X:!++Y))(Y=!++n)


        Try it online!






        share|improve this answer














        JavaScript (ES6), 228 bytes



        Takes input as (n,x,y,[[dir,len],[dir,len],...]) where directions are encoded counterclockwise from $0$ for South to $7$ for South-West.



        Outputs a string with 0 for a boundary, 1 for a trace and 3 for the final position.





        (n,x,y,a)=>(g=X=>Y>n?'':(Y%n&&X%n&&a.map(([d,l],i)=>(M=H=>(h-X|v-Y||(k|=a[i+!l]?1:3),l--&&M(H=(h+H)%n?H:-H,h+=H,v+=V=(v+V)%n?V:-V)))(~-(D='12221')[d],V=~-D[d+2&7]),h=x+n/2,v=n/2-y,k=' ')&&k)+(X<n?'':`
        `)+g(X++<n?X:!++Y))(Y=!++n)


        Try it online!







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 4 secs ago

























        answered 24 mins ago









        Arnauld

        64.9k581274




        64.9k581274



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f172837%2ftrack-an-object-in-2d-space%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery