Žb_3Ý3*+ΣŽBÙNè}U4LÃ23SD1«‡©D4Å?Vε¾ˆ3%iŽb[D>‚¾èy≠i¼¼}ëy<iX¾è¼ëXÀ¾è.¼]¾ˆç':š®õQi`ë">V<^"¾èªDgÅ2¯¥2Q1Ý«-ćY+šsŽ9¦¯èYi¦6š}Λ
Sigh.. what a mess. Almost don't want to post it, but took too much time to not post it now. The challenge has quite a bit of edge cases I wasn't expecting when I started with it.. Can definitely be golfed (by a lot), though.
-3 bytes thanks to @Grimy.
-2 bytes by using ║
(unicode value 9553) instead of ‖
(unicode value 8214). If this is not allowed, 2 bytes has to be added again.
Try it online. (No test suite for all test cases at once, because there is no way to reset the Canvas, so outputs would overlap..)
Explanation:
Žb_ # Push the compressed integer 9556
3Ý # Push the list [0,1,2,3]
3* # Multiplied by 3: [0,3,6,9]
+ # Added to the integer: [9556,9559,9562,9565]
Σ } # Sort it:
ŽBÙNè # Based on the order in the compressed integer 3021
# (so it's now in the order [9559,9565,9562,9556] ("╗╝╚╔"))
U # Then pop and store it in variable `X`
4L # Push a list [1,2,3,4]
à # And only keep those digits from the (implicit) input-string
23S # Push [2,3]
D1« # Duplicate it, and append a 1 to each: [21,31]
‡ # Replace all "2" with "21" and all "3" with "31"
© # Store the string in variable `r` (without popping) to use later on
D4Å? # Check if it starts with a 4 (without popping by duplicating first)
V # Pop and store it in variable `Y` to use later on
ε # Map over each digit:
¾ˆ # Add counter `c` to the global array
# (counter `c` is 0 by default)
3%i # If the current digit is a 1 or 4:
Žb[ # Push compressed integer 9552
D>‚ # Pair it with it's increment: [9552,9553] ("═║")
¾è # And index the counter `c` into it
y≠i } # If the current digit is NOT 1 (so it's a 4):
¼¼ # Increase counter `c` twice to reverse the direction
ëy<i # Else-if the current digit is a 2:
X¾è # Index the counter `c` into the list of variable `X`
¼ # And increase the counter `c` by 1
ë # Else (the current digit is a 3):
X # Push the list of variable `X`
À # Rotated it once toward the left: [9565,9562,9556,9559] ("╝╚╔╗")
¾è # Index the counter `c` into it again
.¼ # And decrease counter `c` by 1
] # Close all if-else statements and the map
¾ˆ # And also add the current counter `c` to the global array after the map
ç # Now convert all integers to ASCII characters with these unicode values
':š '# Prepend a ":" to this list
®õQi # If the input we saved in variable `r` was empty:
` # Push (and implicitly output) this single ":" as result
ë # Else:
">V<^"¾è # Index the counter `c` in the string ">V<^"
ª # And append it to the list
Dg # Get the length of the list (without popping by duplicating first)
Å2 # Create a list with that many 2s
¯¥ # Push the deltas/forward differences of the global array
2Q # Check if a delta is equal to 2 (which means we reversed direction)
# (1 if truthy; 0 if falsey)
1Ý« # Append a trailing [0,1]
- # Subtract them from the list of 2s
Y # If the input started with a 4:
ć +š # Increase the very first integer by 1 (from 1 to a 2)
s # Swap this integer list for the lengths and string list on the stack
Ž9¦ # Push compressed integer 2460
¯è # Index each value of the global array into it
Yi } # If the input started with a 4:
¦6š # Replace the first integer with a 6
Λ # Use the Canvas builtin (which is output immediately implicitly)
See this 05AB1E tip of mine (section How to compress large integers?) to understand why Žb_
is 9556
; ŽBÙ
is 3021
; Žb[
is 9552
; and Ž9¦
is 2460
.
As for a brief explanation of the Canvas builtin Λ
and its three arguments:
First argument: length(s): the sizes of the lines we want to draw. Since we have to keep in mind overlapping, we use size 2
for every character, except if we reverse the direction and we want to overlap or for the final character (one of >V<^
), for which we'll use size 1
instead.
Second argument: string(s): the characters we want to display. Which are the characters in this case, with the prepended :
, and if the input wasn't empty/0
the appended appended final character (one of >V<^
).
Third argument: direction(s): the directions these character-lines of the given length should be drawn in. In general we have the directions [0,7]
which map to these directions:
7 0 1
↖ ↑ ↗
6 ← X → 2
↙ ↓ ↘
5 4 3
Which is why we have the integer 2460
for the directions \$[→,↓,←,↑]\$ respectively.
See this 05AB1E tip of mine for a more detailed explanation about the Canvas builtin Λ
.
Any other numbers or letters will be ignored
This is rather annoying. There's enough challenge in the question itself without also having to add filtering the input string \$\endgroup\$2
in your first example make two "steps" forward after turning instead of just one? \$\endgroup\$═
while others use=
. Which one should we use? \$\endgroup\$║
(unicode value 9553) instead of‖
(unicode value 8214) make more sense? The unicode values of the corners are[9559,9565,9562,9556]
, so the═
(unicode value 9552) and║
(unicode value 9553) would align a lot better. See the current output in my 05AB1E answer in comparison to the previous 120 bytes version. \$\endgroup\$