Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

deleted 37 characters in body
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

05AB1E, 30 (削除) 30 (削除ここまで) 27 bytes

εY„\εY.../yk©di®i2^ë6α}Võëˆ]Jā≠>s ̄Λ \yk©di®>·^Võëˆ]Jā≠>s ̄Λ

Try it online. -3 bytes thanks to @Neil.

Try it online. (No test suite with all test cases at once, because the will overlap previous drawings and there isn't a way to reset it.)

ε # Map over each character `y` of the (implicit) input:
 # (implicitly push the current character `y`)
 Y # Push variable `Y` (which starts at 2)
 „\.../yk \yk # Get the (0-based) index of character `y` in "\/"/ \",
 # or -1 if it's not present in this string
 © © # Store this index in variable `®` (without popping)
 di di # Pop and if this index is non-negative:
  ®i # If index `®` is 1 (aka character `y` is "/" or "\"):
 ® 2^ # Push Bitwise-XORindex Y`®` by(0 for "/" or 2 for "\")
 ë > # ElseIncrease (indexit `®`by is1 0,(1 akafor character"/" `y`or is3 for "\"):
  #· # Take theDouble absoluteit different(2 offor Y"/" withor 6 insteadfor "\")
 } ^ # Close theBitwise-XOR innerY if-elseby statementthis
 V # Pop and store this value as new `Y`
 õ # Push an empty string ""
 ë ë # Else (aka `y` is a letter, "_", or "-"):
 ˆ ˆ # Pop and add the current `Y` to the global array
] # Close both the outer if-else statement and map
 J # Join the characters (and empty strings) together,
 # which will be the input-string without the "\" and "/"
 ā # Push a list in the range [1,length] (without popping)
 ≠ # Check for each integer that it's NOT 1: [0,1,1,1,...]
 > # Increase each by 1: [1,2,2,2,...]
 s # Swap so the string is at the top of the stack again
 ̄ # Push the global array
 Λ # Use the Canvas builtin with these three arguments
 # (after which the result is implicitly output immediately)

εY„\εY.../yk©di®i2^ë6α}Võëˆ]Jā≠>s ̄ \yk©di®>·^Võëˆ]Jā≠>s ̄ with example input boa/co\ns/t\rictor creates the following three Canvas arguments:

  • For / I do a bitwise-XOR with 2, changing the directions as: 0⇒2; 2⇒0; 4⇒6; 6⇒4 - try it online;
  • For \ I do an absolute differenta bitwise-XOR with 6, changing the directions as: 0⇒6; 2⇒4; 4⇒2; 6⇒0 - try it online try it online;
  • For letters, -, or _, the direction remains the same.

05AB1E, 30 bytes

εY„\/yk©di®i2^ë6α}Võëˆ]Jā≠>s ̄Λ

Try it online. (No test suite with all test cases at once, because the will overlap previous drawings and there isn't a way to reset it.)

ε # Map over each character `y` of the (implicit) input:
 # (implicitly push the current character `y`)
 Y # Push variable `Y` (which starts at 2)
 „\/yk # Get the (0-based) index of character `y` in "\/",
 # or -1 if it's not present in this string
 © # Store this index in variable `®` (without popping)
 di # Pop and if this index is non-negative:
  ®i # If index `®` is 1 (aka character `y` is "/"):
 2^ # Bitwise-XOR Y by 2
 ë # Else (index `®` is 0, aka character `y` is "\"):
  # Take the absolute different of Y with 6 instead
 } # Close the inner if-else statement
 V # Pop and store this value as new `Y`
 õ # Push an empty string ""
 ë # Else (aka `y` is a letter, "_", or "-"):
 ˆ # Pop and add the current `Y` to the global array
] # Close both the outer if-else statement and map
 J # Join the characters (and empty strings) together,
 # which will be the input-string without the "\" and "/"
 ā # Push a list in the range [1,length] (without popping)
 ≠ # Check for each integer that it's NOT 1: [0,1,1,1,...]
 > # Increase each by 1: [1,2,2,2,...]
 s # Swap so the string is at the top of the stack again
 ̄ # Push the global array
 Λ # Use the Canvas builtin with these three arguments
 # (after which the result is implicitly output immediately)

εY„\/yk©di®i2^ë6α}Võëˆ]Jā≠>s ̄ with example input boa/co\ns/t\rictor creates the following three Canvas arguments:

  • For / I do a bitwise-XOR with 2, changing the directions as: 0⇒2; 2⇒0; 4⇒6; 6⇒4 - try it online;
  • For \ I do an absolute different with 6, changing the directions as: 0⇒6; 2⇒4; 4⇒2; 6⇒0 - try it online;
  • For letters, -, or _, the direction remains the same.

05AB1E, (削除) 30 (削除ここまで) 27 bytes

εY.../ \yk©di®>·^Võëˆ]Jā≠>s ̄Λ

-3 bytes thanks to @Neil.

Try it online. (No test suite with all test cases at once, because the will overlap previous drawings and there isn't a way to reset it.)

ε # Map over each character `y` of the (implicit) input:
 # (implicitly push the current character `y`)
 Y # Push variable `Y` (which starts at 2)
 .../ \yk # Get the (0-based) index of character `y` in "/ \",
 # or -1 if it's not present in this string
 © # Store this index in variable `®` (without popping)
 di # Pop and if this index is non-negative (aka `y` is "/" or "\"):
 ® # Push index `®` (0 for "/" or 2 for "\")
 > # Increase it by 1 (1 for "/" or 3 for "\")
 · # Double it (2 for "/" or 6 for "\")
 ^ # Bitwise-XOR Y by this
 V # Pop and store this value as new `Y`
 õ # Push an empty string ""
 ë # Else (aka `y` is a letter, "_", or "-"):
 ˆ # Pop and add the current `Y` to the global array
] # Close both the outer if-else statement and map
 J # Join the characters (and empty strings) together,
 # which will be the input-string without the "\" and "/"
 ā # Push a list in the range [1,length] (without popping)
 ≠ # Check for each integer that it's NOT 1: [0,1,1,1,...]
 > # Increase each by 1: [1,2,2,2,...]
 s # Swap so the string is at the top of the stack again
 ̄ # Push the global array
 Λ # Use the Canvas builtin with these three arguments
 # (after which the result is implicitly output immediately)

εY.../ \yk©di®>·^Võëˆ]Jā≠>s ̄ with example input boa/co\ns/t\rictor creates the following three Canvas arguments:

  • For / I do a bitwise-XOR with 2, changing the directions as: 0⇒2; 2⇒0; 4⇒6; 6⇒4 - try it online;
  • For \ I do a bitwise-XOR with 6, changing the directions as: 0⇒6; 2⇒4; 4⇒2; 6⇒0 - try it online;
  • For letters, -, or _, the direction remains the same.
deleted 2 characters in body
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394
  • For / I do a bitwise-XOR with 2, changing the directions as: 0⇒2; 2⇒0; 4⇒6; 6⇒4 - try it online;
  • For \ I do an absolute different with 66, changing the directions as: 0⇒6; 2⇒4; 4⇒2; 6⇒0 - try it online;
  • For letters, -, or _, the direction remains the same.
  • For / I do a bitwise-XOR with 2, changing the directions as: 0⇒2; 2⇒0; 4⇒6; 6⇒4 - try it online;
  • For \ I do an absolute different with 6, changing the directions as: 0⇒6; 2⇒4; 4⇒2; 6⇒0 - try it online;
  • For letters, -, or _, the direction remains the same.
  • For / I do a bitwise-XOR with 2, changing the directions as: 0⇒2; 2⇒0; 4⇒6; 6⇒4 - try it online;
  • For \ I do an absolute different with 6, changing the directions as: 0⇒6; 2⇒4; 4⇒2; 6⇒0 - try it online;
  • For letters, -, or _, the direction remains the same.
Source Link
Kevin Cruijssen
  • 136.2k
  • 14
  • 154
  • 394

05AB1E, 30 bytes

εY„\/yk©di®i2^ë6α}Võëˆ]Jā≠>s ̄Λ

Try it online. (No test suite with all test cases at once, because the will overlap previous drawings and there isn't a way to reset it.)

Explanation:

ε # Map over each character `y` of the (implicit) input:
 # (implicitly push the current character `y`)
 Y # Push variable `Y` (which starts at 2)
 „\/yk # Get the (0-based) index of character `y` in "\/",
 # or -1 if it's not present in this string
 © # Store this index in variable `®` (without popping)
 di # Pop and if this index is non-negative:
 ®i # If index `®` is 1 (aka character `y` is "/"):
 2^ # Bitwise-XOR Y by 2
 ë # Else (index `®` is 0, aka character `y` is "\"):
 6α # Take the absolute different of Y with 6 instead
 } # Close the inner if-else statement
 V # Pop and store this value as new `Y`
 õ # Push an empty string ""
 ë # Else (aka `y` is a letter, "_", or "-"):
 ˆ # Pop and add the current `Y` to the global array
] # Close both the outer if-else statement and map
 J # Join the characters (and empty strings) together,
 # which will be the input-string without the "\" and "/"
 ā # Push a list in the range [1,length] (without popping)
 ≠ # Check for each integer that it's NOT 1: [0,1,1,1,...]
 > # Increase each by 1: [1,2,2,2,...]
 s # Swap so the string is at the top of the stack again
 ̄ # Push the global array
 Λ # Use the Canvas builtin with these three arguments
 # (after which the result is implicitly output immediately)

Additional explanation of the Canvas builtin Λ/:

It takes 3 arguments to draw an ASCII shape:

  1. Length of the lines we want to draw
  2. Character/string to draw
  3. The direction to draw in, where each digit represents a certain direction:
7 0 1
 ↖ ↑ ↗
6 ← X → 2
 ↙ ↓ ↘
5 4 3

εY„\/yk©di®i2^ë6α}Võëˆ]Jā≠>s ̄ with example input boa/co\ns/t\rictor creates the following three Canvas arguments:

  1. Lengths: [1,2,2,2,2,2,2,2,2,2,2,2,2,2]
  2. Chars to draw: [b,o,a,c,o,n,s,t,r,i,c,t,o,r]
  3. Directions: [2,2,2,0,0,6,6,4,2,2,2,2,2,2]

So it'll draw b of length 1 in direction 2/→:

b

Then o of length 2-1 still in direction 2/→:

bo

Likewise for a:

boa

Then for c it changes direction to 0/↑:

 c
boa

Then o of length 2-1 still in direction 0/↑:

 o
 c
boa

Then for n it changes directions again, this time to 6/←:

 no
 c
boa

Etc.

See this 05AB1E tip of mine to learn more about the Canvas builtin.

As for how I change directions based on the / or \:

  • For / I do a bitwise-XOR with 2, changing the directions as: 0⇒2; 2⇒0; 4⇒6; 6⇒4 - try it online;
  • For \ I do an absolute different with 6, changing the directions as: 0⇒6; 2⇒4; 4⇒2; 6⇒0 - try it online;
  • For letters, -, or _, the direction remains the same.

AltStyle によって変換されたページ (->オリジナル) /