| Bytes | Lang | Time | Link |
|---|---|---|---|
| 013 | Retina | 160423T224453Z | Downgoat |
| 043 | Dyalog APL | 250924T034241Z | Aaron |
| 014 | Vyxal | 250923T003737Z | emanresu |
| 063 | V vim | 250120T194922Z | Fmbalbue |
| 436 | Bespoke | 250119T042535Z | Josiah W |
| 070 | Python 3 | 250117T035639Z | ryyyn |
| 016 | Vyxal 3 | 250117T114455Z | Themooni |
| 053 | K ngn/k | 250117T095929Z | oeuf |
| 073 | PowerShell Core | 250117T050857Z | Julian |
| 015 | Japt v2.0a0 R | 230213T222829Z | Shaggy |
| 089 | brev | 230212T133423Z | Sandra |
| 064 | ><> | 160509T160736Z | Sok |
| 056 | Ruby | 160423T212555Z | anon |
Retina, 13 bytes
\d
$*
/
¶
|
Explanation
The first part (note the trailing space):
\d
$*
is to convert a digit to the specific number of spaces. Retina has a $* feature to repeat. The way it works is: <num>$*<char> if there is no <num>, Retina will assume $& or the matched string, in this case the matched number.
The next part:
/
¶
is pretty simple, it replaces all / with ¶ which is a newline.
The last part works the same:
|
This will replace everything (hence why there is nothing on the first line) with |. Putting a | everywhere.
Dyalog APL, 43 bytes
{↑{∊'|',⍨'|',¨∊⍴∘' '⍤⍎¨@{⍵∊⎕D}⍵}¨'/'(≠⊆⊢)⍵}
'/'( )⍵ # Apply this train with '/' on the left and input on the right
(≠⊆⊢) # Partition the right arg where the left and right args do not match
{ }¨ # For each of these
@ ⍵ # Replace the elements of the vector
{⍵∊⎕D} # where the element is in the list of digits
¨ # with each of them
⍎ # execute (turn the digit char to a number)
⍴∘' '⍤ # and take that many spaces
∊ # Enlist
'|',¨ # Prepend a pipe to each character
'|',⍨ # and append a pipe at the end
∊ # Enlist
↑ # And finally mix to make it look nice
💎
Created with the help of Luminespire.
Vyxal, 14 bytes
8ɾ:ð*Ŀ‛/
*¤\|V
Unlike quite a few of the other golflang answers, this performs replacements on the whole string. It contains a literal newline, which I've replaced with ¶ in the below explanation.
Ŀ # Replace each of
8ɾ # [1, 2, ... 8]
:ð* # with that many spaces
* # Ring translate, moving each character in the key to the next, with key
‛/¶ # "/<newline>" - i.e. replacing /s with newlines
V # Replace
¤ # the empty string - i.e. at every point in the string
\| # with a pipe character (trick stolen from retina answers)
V (vim), 63 bytes
:s/\d/\=repeat(' ',submatch(0))/g
:s/\//\r/g
:%s/./|&/g
:%s/$/|
-17 bytes thanks to Aaroneous Miller
This code probably can be golfed further, and I would appreciate if you could let me know that you found a way to golf it.
Explanation:
:s/[1-8]/\=repeat(' ',str2nr(submatch(0)))/g
Replace the digit with a number of spaces depending on the digit.
:s/\//\r/g
Replace the slashes with newlines.
:%s/./|&/g
Insert | to the left of every non-newline character.
:%s/$/|
Insert | to the left of every newline
Bespoke, 436 bytes
fantasy matches
and now,I do Paul Morphy
in game v.s,I do Hans Neimann
if,sometime anywhere,they v.s?oh,who to win?Im stumped
laughable,but oh,I fantasized chess is in this way
if Garry Kimovich Kasparov is playing,he is good
did he play Vladimir Fedoseev?no
however,if entering fantasy,champion Magnus Carlsen plausibly can go play everybody
possibly Anish Giri v.s me,you,or any ol players
but imagine one matchup:you versus me,Game I
(I tried name-dropping as many great chess players as I thought made sense.)
The general strategy is to map each input character onto some other character, and output | followed by that mapped-to character. / maps to a newline, any digit maps to , and any other character maps to itself.
If the input character is a digit, 49 is subtracted from its codepoint, and that value is stored onto the heap; if some nonzero value is at that place on the heap, that value is decremented, is outputted, and the next input character is not yet consumed.
With the way I detect the / character, EOF (-1) leads to the same code path. So the way I halt on EOF here is by adding 1 to the codepoint, and mapping to 10 modulo that value; this leads to an Invalid stack argument: 0 error upon EOF.
Python 3, 70 bytes
lambda B:''.join([(ord(c)-48)*'| 'or'|\n','|'+c][c>'A']for c in B)+'|'
Edit: saved bytes by returning string instead of printing
It is shorter to append the vertical bars while iterating over the characters, rather than using split/join or translate.
Using int() to get the number of spaces has the downside that we must short circuit before calling int on invalid input to avoid exception:
(c=='/')*'|\n'or(c>'A')*('|'+c)or int(c)*'| ' # long
Instead, we can use ord() and abuse the fact that a string multiplied by a negative number is the empty string to evaluate no matter what.
(So when c='/', (ord(c)-48)*'| ' evaluates to '')
Vyxal 3, 16 bytes
-13 bytes by lyxal
'/sƛ¨E␣×∑'|9×$I,
Split on "/"
To each line:
Eval each character
And push either number spaces or the original character
Join that into a single string
And interleave with 9 "|"s (to place a pipe between each character + beginning and end)
Print the line
PowerShell Core, 73 bytes
$ofs="|"
"|$($args|%{switch -r($_){/{"
"}\d{," "*+"$_"}"[a-z]"{"$_"}}})|"
Another approach using Invoke-Expression for 89 bytes
Japt v2.0a0 -R, 15 bytes
r\dȰçÃrP'| q'/
r\dȰçÃrP'| q'/ :Implicit input of string U
r :Replace
\d : Regex /[0-9]/g
È : Pass each match through a function
° : Postfix increment (to convert from string to integer)
ç : Repeat a space that many time
à :End replace
r :Replace
P : Empty string
'| : With "|"
q'/ :Split on "/"
:Implicit output, joined with newlines
brev, 89 bytes
(fn(print(strse x'num(->(m 0)string->number(make-string #\ ))"."(c conc "|")"/""\n")"|"))
><>, 64 bytes
<v?(0:i
r\
"<o-*=@"%/": v?*(@)@":/"::;?(0:o"|
^~?="0":-1o" "<
4 wasted bytes due to alignment issues, not sure how to golf them out though. ¯\_(ツ)_/¯
Ruby - 75 82 78 76 75 62 59 58 57 56 bytes
->n{"|#{n.gsub(/\d|
/){' '*$&.hex}.chars*?|}|".tr'/',$/}
Saved a few bytes thanks to Ventero
Let me explain (with \n replacing the literal newline):
->n{"...".tr'/',$/}
This implicitly returns the value of the string, with each / replaced with a newline (by default, $/ contains a newline)
"|#{...}|"
This is super simple; it's just a string containing a pipe, string interpolation, and another pipe. The string interpolation is evaluated
n.gsub(/\d|\n/){' '*$&.hex}...
This replaces every number with that many spaces. I can save a few bytes by also finding newlines here; because hex returns 0 if the string isn't a valid number, when it finds a newline –- i.e. the one at the end of the result of gets –- it replaces it with a 0-length string, effectively deleting it. Without this, there would be a trailing pipe.
$& is a magic variable which represents the complete text of the latest variable match, which lets me save a byte by eliminating |d|. I can save another byte by using .hex instead of .to_i, which works because every number is less than 9, which means that hex and decimal have the same values.
.chars*?|
This puts a pipe between every character. Note that this is what puts the pipes on either side of the lines (except the first and last) because the slashes, which eventually turn into newlines through tr, count as characters, and are therefore surrounded by pipes. The ?| just means "the one-character string "|"".
And... that's it. It's a frankly scandalously simple program. It just uses a lot of sneaky syntax tricks.