Skip to main content
deleted 121 characters in body
Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

05AB1E, 37 37 35 (or 4242 38) bytes

4238 bytes: Input as comma-separated string, as mentioned in the challenge description:

',¡Dg<Uεć"NESW"skxs"^>v<"èrXNÊ+¡εć"NESW"skxs"^>v<"è)}øÁ`Λ1'X0ΛøR`ā¤Ê+ŠΛ1'X0Λ

Try it online.Try it online.

3735 bytes: Input as a list of pairs of direction-character and distant-integer, by removing the first three bytes ',¡:

εć"NESW"skxs"^>v<"èrIg<NÊ+)}øÁ`Λ1'X0Λ

Try it online.
Try it online.

',¡           '# Split the (implicit) input-string on commas
   D           # Duplicate the list
    g          # Pop the copy, and push its length
     <         # Decrease it by 1
      U        # Pop and store it in variable `X`
   ε           # Map over each string:
    ć          #  Extract its head; push distant and direction-char separately
     "NESW"sk  #  Get the 0-based index of the character in "NESW"
             x #  Double it (without popping)
     s         #  Swap so the index is at the top again
      "^>v<"è  #  Convert the index to the correct output character
     r)         #  ReverseWrap all three values into a list
    }ø         # After the stackmap: sozip/transpose the distantlist isof attriplets; theswapping toprows/columns
      XR        #  PushReverse length-1the fromlist variableof `X`triplets
       `     #  Check# thatPop theand 0-basedpush map-indexall isthree NOTlists equalsseparately to this
the stack
        ā      #  (akaPush 0a iflist it'sin the last iteration; 1range otherwise)[1,length]
         +¤     # Push Addits thatlast toitem (without popping the distantlist)
     )     Ê    # Check Wrapfor alleach threethat valuesit's intoNOT aequal listto this last item
           +   # AfterAdd the map:values zip/transposeat the listsame ofpositions
 triplets; swapping rows/columns
      Á      # (so #1 Rotateis itadded onceto towardsall distances, except the rightlast one)
       ` Š      # Pop and pushTriple-swap allthe three lists separately toon the stack
        Λ Λ     # Canvas builtin with these three arguments
               # (which is output immediately)
1'X0Λ         '# And another Canvas builtin with arguments 1,"X",0
               # (which is done on top of the other Canvas and also output)

For example: input E2,N4,E5,S2,W1,S3 will for ',¡Dg<Uεć"NESW"skxs"^>v<"èrXNÊ+¡εć"NESW"skxs"^>v<"è)}øÁ`øR`ā¤Ê+Š result in the three lists:

05AB1E, 37 (or 42) bytes

42 bytes: Input as comma-separated string, as mentioned in the challenge description:

',¡Dg<Uεć"NESW"skxs"^>v<"èrXNÊ+)}øÁ`Λ1'X0Λ

Try it online.

37 bytes: Input as a list of pairs of direction-character and distant-integer:

εć"NESW"skxs"^>v<"èrIg<NÊ+)}øÁ`Λ1'X0Λ

Try it online.

',¡           '# Split the (implicit) input-string on commas
   D           # Duplicate the list
    g          # Pop the copy, and push its length
     <         # Decrease it by 1
      U        # Pop and store it in variable `X`
   ε           # Map over each string:
    ć          #  Extract its head; push distant and direction-char separately
     "NESW"sk  #  Get the 0-based index of the character in "NESW"
             x #  Double it (without popping)
     s         #  Swap so the index is at the top again
      "^>v<"è  #  Convert the index to the correct output character
     r         #  Reverse the stack so the distant is at the top
      X        #  Push length-1 from variable `X`
            #  Check that the 0-based map-index is NOT equals to this
               #  (aka 0 if it's the last iteration; 1 otherwise)
         +     #  Add that to the distant
     )         #  Wrap all three values into a list
             # After the map: zip/transpose the list of triplets; swapping rows/columns
      Á        # Rotate it once towards the right
       `       # Pop and push all three lists separately to the stack
        Λ      # Canvas builtin with these three arguments
               # (which is output immediately)
1'X0Λ         '# And another Canvas builtin with arguments 1,"X",0
               # (which is done on top of the other Canvas and also output)

For example: input E2,N4,E5,S2,W1,S3 will for ',¡Dg<Uεć"NESW"skxs"^>v<"èrXNÊ+)}øÁ` result in the three lists:

05AB1E, 37 35 (or 42 38) bytes

38 bytes: Input as comma-separated string, as mentioned in the challenge description:

',¡εć"NESW"skxs"^>v<"è)}øR`ā¤Ê+ŠΛ1'X0Λ

Try it online.

35 bytes: Input as a list of pairs of direction-character and distant-integer, by removing the first three bytes ',¡:
Try it online.

',¡           '# Split the (implicit) input-string on commas
   ε           # Map over each string:
    ć          #  Extract its head; push distant and direction-char separately
     "NESW"sk  #  Get the 0-based index of the character in "NESW"
             x #  Double it (without popping)
     s         #  Swap so the index is at the top again
      "^>v<"è  #  Convert the index to the correct output character
     )         #  Wrap all three values into a list
    }ø         # After the map: zip/transpose the list of triplets; swapping rows/columns
      R        # Reverse the list of triplets
       `       # Pop and push all three lists separately to the stack
        ā      # Push a list in the range [1,length]
         ¤     # Push its last item (without popping the list)
          Ê    # Check for each that it's NOT equal to this last item
           +   # Add the values at the same positions
               # (so 1 is added to all distances, except the last one)
        Š      # Triple-swap the three lists on the stack
         Λ     # Canvas builtin with these three arguments
               # (which is output immediately)
1'X0Λ         '# And another Canvas builtin with arguments 1,"X",0
               # (which is done on top of the other Canvas and also output)

For example: input E2,N4,E5,S2,W1,S3 will for ',¡εć"NESW"skxs"^>v<"è)}øR`ā¤Ê+Š result in the three lists:

Source Link
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

05AB1E, 37 (or 42) bytes

42 bytes: Input as comma-separated string, as mentioned in the challenge description:

',¡Dg<Uεć"NESW"skxs"^>v<"èrXNÊ+)}øÁ`Λ1'X0Λ

Try it online.

37 bytes: Input as a list of pairs of direction-character and distant-integer:

εć"NESW"skxs"^>v<"èrIg<NÊ+)}øÁ`Λ1'X0Λ

Try it online.

Explanation (of the strict I/O program):

',¡           '# Split the (implicit) input-string on commas
   D           # Duplicate the list
    g          # Pop the copy, and push its length
     <         # Decrease it by 1
      U        # Pop and store it in variable `X`
   ε           # Map over each string:
    ć          #  Extract its head; push distant and direction-char separately
     "NESW"sk  #  Get the 0-based index of the character in "NESW"
             x #  Double it (without popping)
     s         #  Swap so the index is at the top again
      "^>v<"è  #  Convert the index to the correct output character
     r         #  Reverse the stack so the distant is at the top
      X        #  Push length-1 from variable `X`
       NÊ      #  Check that the 0-based map-index is NOT equals to this
               #  (aka 0 if it's the last iteration; 1 otherwise)
         +     #  Add that to the distant
     )         #  Wrap all three values into a list
    }ø         # After the map: zip/transpose the list of triplets; swapping rows/columns
      Á        # Rotate it once towards the right
       `       # Pop and push all three lists separately to the stack
        Λ      # Canvas builtin with these three arguments
               # (which is output immediately)
1'X0Λ         '# And another Canvas builtin with arguments 1,"X",0
               # (which is done on top of the other Canvas and also output)

The Canvas builtin Λ takes three arguments:

  1. Length(s): which are the modified distances (+1 for every distance except the last one, since the Canvas builtin draws with overlapping corners)
  2. The characters we want to display
  3. The directions to draw in, which is in this case is \$0\$=North; \$2\$=South; \$4\$=South; \$6\$=West.

For example: input E2,N4,E5,S2,W1,S3 will for ',¡Dg<Uεć"NESW"skxs"^>v<"èrXNÊ+)}øÁ` result in the three lists:

  1. Lengths: [3,5,6,3,2,3]
  2. Characters: [">","^",">","v","<","v"]
  3. Directions: [2,0,2,4,6,4]

And will print them as:

  >>>>>v
  ^    v
  ^   v<
  ^   v 
>>^   v 

After which the 1'X0Λ will overwrite the final v with X.

See this 05AB1E tip of mine for an in-depth explanation of the Canvas builtin.