| Bytes | Lang | Time | Link |
|---|---|---|---|
| 023 | APLDyalog Unicode | 250521T120019Z | Mat_rdv |
| 016 | Jelly | 210517T165108Z | Unrelate |
| 017 | 05AB1E | 210628T141841Z | Kevin Cr |
| 021 | Vyxal aṠD | 210518T161045Z | a stone |
| 074 | Mathematica | 210521T133252Z | John |
| nan | Python 3.8 prerelease | 210517T225703Z | Jakque |
| 056 | AWK | 210518T015805Z | Pedro Ma |
| 096 | Excel Insider Beta | 210517T223703Z | Axuary |
| 061 | JavaScript Node.js | 210517T160931Z | user1006 |
| 019 | Stax | 210518T052334Z | Razetime |
| 021 | Pip rl | 210518T033810Z | DLosc |
| nan | J | 210517T215928Z | Jonah |
| 054 | JavaScript ES6 | 210517T231719Z | Arnauld |
| 018 | Jelly | 210517T153634Z | hyperneu |
| 018 | Jelly | 210517T152731Z | caird co |
| 020 | Charcoal | 210517T175443Z | Neil |
| 019 | Retina 0.8.2 | 210517T161302Z | Neil |
| 080 | /// | 210517T172602Z | nph |
| 025 | Perl 5 p Mutf8 | 210517T171204Z | Nahuel F |
| 025 | sed 4.2.2 | 210517T165217Z | Digital |
| 024 | 05AB1E | 210517T162620Z | Makonede |
APL(Dyalog Unicode), 23 bytes SBCS
'_\¯/'⌷⍨∘⊂⊢×{5|2⊥⍵}⌺3⍤1
This function operates with boolean arrays and needs 0 as the index origin (⎕IO←0).
Explanation
⍤1 Rank 1 (for each row)
⌺3 Stencil (e.g. 0 1 1 0 → (0 0 1) (0 1 1) (1 1 0) (1 0 0))
{ } direct function
⍵ right argument (triplet)
2⊥ Decode (from binary)
| Modulo
5
{5|2⊥⍵} transforms 1 1 0 → 1, 1 1 1 → 2, 0 1 1 → 3
× Multiply
⊢ right argument (initial array)
⌷⍨∘⊂ Select elements from the left argument by indices on the right
'_\¯/'
Jelly, 16 bytes
Ż<ƝoḤU)⁺ị“\/Ø-_”
Uses hyphens instead of macrons. Takes a good deal of inspiration from hyper-neutrino's answer, so don't forget to send her some votes. Feels like there's got to be some way to shave a byte off the string at the end, with the right replacement for oḤ...
) For each line,
⁺ twice:
Ż prepend a 0,
Ɲ then for each pair of neighboring elements
< is the second greater than the first?
o Replace zeroes with corresponding elements of
Ḥ the line doubled,
U and reverse.
ị Modular 1-index into
“\/Ø-_ "\/Ø-_".
(0 -> _, 1 -> \, 2 -> /, 4 -> -)
05AB1E, 17 bytes
γε¬i¦¦…/ÿ\]JT„¯_‡
I/O as a multiline string.
Explanation:
γ # Split the (implicit) input-string into equal adjacent parts
# i.e. "0110\n1111" → ["0","11","0","\n","1111"]
ε # Map each part to:
¬ # Get its first character (without popping)
i # If this is a 1:
¦¦ # Remove two characters from this string
…/ÿ\ # Surround it with leading "/" and trailing "\"
] # Close both the if-statement and map
# → ["0","/\","0","\n","/11\"]
J # Join everything back together
# → "0/\0\n/11\"
T ‡ # Then transliterate the characters "1" and "0"
„¯_ # to the characters "¯" and "_"
# → "_/\_\n/¯¯\"
# (after which the result is output implicitly)
Vyxal aṠD, 21 bytes
-1 from Aaron Miller
ƛĠƛ⌊ḣ$NpṫdJ`_¯\/`$İ;f
Heavily inspired by @caird coinheringaahing's Jelly answer.
Outputs a list of lines containing a list of characters in each line. Uses the actual macron!
ƛĠƛ⌊ḣ$NpṫdJ`_¯\/`$İ;f
ƛ For each line of (implicit) input...
Ġƛ ; For each group of consecutive characters...
⌊ Convert each character to an integer (so double and negate work)
N Negate...
ḣ$ p the first element of the group.
d Double...
ṫ J the last element of the group.
İ Index each element...
`_¯\/`$ in "_¯\/" (negative indices start from the back)
f Flatten the list of groups to a lists of chars
Mathematica, 74 bytes
StringReplace[#,{"101"->"\_/","01"->"_/","10"->"¯\\","0"->"_","1"->"¯"}]&
Python 3.8 (pre-release), 80 bytes (but actually 79 because ¯ is counted as a 1 byte char in this challenge)
import re
while r:=re.sub:print(r(*"0_",r(*"1¯",r("1(1*)1",r"/\1\\",input()))))
Because we love re.sub :)
Old solution : 94 bytes (but actually 93, you know the song ...)
I don't know why but I thought a pure vanilla python solution would beat a solution using regex ... I was wrong.
while r:=str.replace:print(r(r(r(r(f"0{input()}0","10","\\0"),"01","0/")[1:-1],*"1¯"),*"0_"))
Nothing too crazy here, just a few str.replace, and some str.replace and even more str.replace
AWK, 56 bytes, 54 by the rules
gsub(0,"_")gsub(1,"/\\")gsub(/\\\//,"¯")gsub("/¯","/")
Substitutes: all 0 to _; all 1 to /\; all \/ to ¯; and, finally, all /¯ to /.
AWK, 52 bytes, 51 by the rules
gsub("01","0/")gsub(10,"\\0")gsub(0,"_")gsub(1,"¯")
Thanks to DLsoc for a 52 bytes/51 characters version.
Excel (Insider Beta), 139 96 bytes
=LET(s,LAMBDA(t,x,y,SUBSTITUTE(t,x,y)),s(s(s(s(s(A2,101,"\_/"),10,"\_"),0&1,"_/"),0,"_"),1,"-"))
Had to spend quite a few bytes shortening the SUBSTITUTE function. Originally, I thought you had to adapt to any two characters which is what I did below.
=LET(s,LAMBDA(t,x,y,SUBSTITUTE(t,x,y)),a,LEFT(A2),b,LEFT(s(s(A2,a,""),"
","")),s(s(s(s(s(A2,b&a&b,"\_/"),b&a,"\_"),a&b,"_/"),a,"_"),b,"-"))
JavaScript (Node.js), 71 65 61 bytes
n=>n.replace(/./g,(e,i)=>+e?+n[i+1]?+n[i-1]?'-':'/':'\\':'_')
How it works
Replaces every letter. For each letter in question: if the numerical representation is falsy (0) then replace with _, otherwise use a simple ternary to find the correct character to use. Uses - instead of macron, you know, just because. Saved 6 bytes by reorganizing and removing assignment to unused a variable. Then saved 4 thanks to a username by entirely getting rid of variables.
Stax, 19 bytes
√E6∙²δ♪₧♂─Ç,áR0Z◄@╖
A regex based solution similar to the Pip and sed answers. Takes a full multiline string.
Pip -rl, 21 "bytes"
gR+X1'/.TM_.'\TRt"¯_"
Explanation
g With -r flag, g is a list of all lines from stdin
R In each line, replace
+X1 regex match of one or more 1's
with this callback function:
TM_ Trim the first and last characters from the match
'/. Prepend /
.'\ Append \
TR Transliterate
t 10
"¯_" into ¯_
Autoprint, one list element per line (-l flag)
JavaScript (ES6), 54 bytes*
* by counting the macron as 1 byte, as allowed in this challenge
s=>s.replace(/./g,(c,i)=>'_/¯\\'[c*=!+s[i+1]-~s[i-1]])
Jelly, 18 bytes
Ż;0ṡ3Ḅ)ị“_./__\-_”
Uses - instead of the macron
Ż;0ṡ3Ḅ)ị“_./__\-_” Main Link; takes a matrix of bits and outputs a list of lines
) For each row
Ż Prepend 0
;0 Append 0
ṡ3 Get overlapping slices of length 3
Ḅ Convert from binary
// basically, the center of the 3-slice is the character itself
// and we need the left and right context to determine if it needs
// to be changed. So ___, __-, -__, and -_- (0, 1, 4, 5) become _,
// _-- (3) becomes /, --_ (6) becomes \, and --- (7) stays as -
ị“_./_.\-_” index into "_./_.\-_", so 1=_ 3=/ 4=_ 5=_ 6=\ 7=- 0=_
// note that Jelly is 1-indexed and indexes wrap around
Jelly, 18 bytes
ŒgḤ1¦€N0¦€)ị“-/\_”
Inputs a matrix of 0 and 1s, outputs a list of lines. Uses - instead of a macron
How it works
ŒgḤ1¦€N0¦€)ị“-/\_” - Main link. Takes a matrix M on the left
) - Over each row R in M:
Œg - Group adjacent equal elements in R
€ - Over each group G in R:
Ḥ - Double:
1¦ - The first value
€ - Over each group G in R:
N - Negate:
0¦ - The last value
For zeros, these are left unchanged.
For ones, the first becomes 2 and the last -1
“-/\_” - Yield the string "-/\_"
ị - Index, 1 based and modularly. This means that:
1 or -3 -> -
2 or -2 -> /
3 or -1 -> \
4 or 0 -> _
Charcoal, 20 bytes
WS⟦⪫E⪪ι0∧κ⪫/\ׯ⁻Lκ²_
Try it online! Link is to verbose version of code. Explanation:
WS⟦
Loop over each input string and print each output on a new line until an empty line is reached. (String array input format would have saved a byte.)
⪫E⪪ι0∧κ⪫/\ׯ⁻Lκ²_
Split each string on 0s, then replace each (non-empty) run of 1s with a run of ¯s wrapped in / and \, finally joining with _s.
Retina 0.8.2, 26 19 bytes
1(1*)1
/$.1$*¯\
0
_
Try it online! Link includes test cases. Edit: Saved 7 bytes with inspiration from @DigitalTrauma. Explanation:
1(1*)1
/$.1$*¯\
Replace a run of 1s with a run of ¯s between / and \.
0
_
Replace 0s with _s.
(Note that Retina uses the ISO-8859-1 code page, so ¯ is 1 byte anyway.)
///, 80 bytes
/0/_//1/a//aaa/a-a//-aa/--a//aa-/a--//-a-/---//a-/\\\/-//-a/-\\\\//aa/\\\/\\\\/
Uses - instead of the macron, as it is allowed.
I'm marking it as 80 bytes because of the required newline at the end of the input.
Perl 5 (-p -Mutf8), 25 bytes, score 24
s|1(1*)1|/\1\\|g;y;01;_¯
Same as Digital Trauma's sed answer, except the trick using semicolon delimiter the last character can be removed.
sed 4.2.2, Score 25
26 bytes, but scoring ¯ as 1, as per note in challenge.
s|1(1*)1|/\1\\|g
y/01/_¯/
05AB1E, 24 bytes
εγεS¬·0ǝR¬(0ǝR}˜"_¯/\"sè
Try it online! Takes input as a list of lines of ones and zeros and outputs as a list of lists of characters in each line.
εγεS¬·0ǝR¬(0ǝR}˜"..."sè # trimmed program
# implicit input...
ε # with each element replaced by...
è # list of characters in...
"..."s # literal...
è # with indices in...
˜ s # flattened...
γ # list of groups of consecutive equal elements in...
# (implicit) current element in map...
ε # with each element replaced by...
R # reversed...
R # reversed...
S # list of characters in...
# (implicit) current element in map...
ǝ # with element at index...
0 # literal...
ǝ # replaced with...
¬ # first element of...
S # list of characters in...
# (implicit) current element in map...
· # doubled...
ǝ # with element at index...
0 # literal...
ǝ # replaced with...
¬ # first element of...
R # reversed...
S # list of characters in...
# (implicit) current element in map...
ǝ # with element at index...
0 # literal...
ǝ # replaced with...
¬ # first element of...
S # list of characters in...
# (implicit) current element in map...
· # doubled...
( # negated
} # exit map
# (implicit) exit map
# implicit output
R} can also be a }í with no change in functionality: Try it online!