| Bytes | Lang | Time | Link |
|---|---|---|---|
| 058 | JavaScript Node.js | 241203T011732Z | l4m2 |
| 073 | Kotlin 1.4.30+ | 241130T051058Z | Joon Yor |
| 076 | C gcc | 170825T082416Z | scottine |
| 063 | JavaScript | 170825T070819Z | user7234 |
| 052 | Vim | 170825T155949Z | Vivian |
| 066 | Python 3 | 170826T175540Z | Chris |
| 050 | Sed | 170825T233744Z | John Gow |
| 088 | Batch | 170825T090214Z | Neil |
| 037 | Alice | 170826T052741Z | Nitrodon |
| 145 | AutoIt | 170825T224842Z | Algirdas |
| 059 | Haskell | 170825T182809Z | betavero |
| 032 | V | 170825T181849Z | nmjcman1 |
| 078 | Ruby | 170825T173830Z | alexande |
| 067 | Ruby | 170825T175929Z | alexande |
| 020 | Pyke | 170825T075635Z | Blue |
| 028 | SOGL V0.12 | 170825T083351Z | dzaima |
| nan | Paradoc v0.2.10 | 170825T161529Z | betavero |
| 029 | Retina | 170825T073207Z | user7234 |
| 044 | Röda | 170825T071332Z | fergusq |
| 069 | Python 2 | 170825T081821Z | Blue |
| 100 | Excel | 170825T095402Z | Wernisch |
| 064 | Python 2 | 170825T070838Z | TFeld |
| 113 | PHP | 170825T092212Z | crazyloo |
| 021 | 05AB1E | 170825T072231Z | Emigna |
| 059 | JavaScript ES6 | 170825T081935Z | Johan Ka |
| 072 | R | 170825T081830Z | rturnbul |
| 081 | Mathematica | 170825T080700Z | ZaMoC |
| 031 | Retina | 170825T072718Z | Dom Hast |
| 077 | R | 170825T074934Z | JAD |
| 039 | Perl 5 | 170825T074149Z | Dom Hast |
JavaScript (Node.js), 58 bytes
a=>a.replace(/./g,a=>[{o:'Rr',n:'rr',p:'-',' ':' - '}[a]])
From user72349's answer but that user is deleted
Kotlin 1.4.30+, 75 73 bytes
{it.split(" ").joinToString(" - "){"Rrrr,-,Rr".split(",")[it[1].code%3]}}
where val f:(String)->String= is the header, this is just a kotlin implementation of the TFeld's Python Solution. Documentation says that .code was introduced in Kotlin 1.5 but I don't know why it works in 1.4.30 in the online test.
C (gcc), 93 77 76 bytes
-2 bytes thanks to Scepheo!
-1 byte thanks to Cyoce!
Takes a NULL terminated **char or equivalent as an input.
f(char**a){for(;*a;*++a&&printf(" - "))printf(**a&6?**a&1?"Rr":"Rrrr":"-");}
Explanations:
f(char**a){
// While the string at the current position is not NULL
for(;*a;
// Advances the pointer to the next string
// Then if the current string is not NULL, prints a delimiter
*++a&&printf(" - ")
)
/*
If the 1st char of the string is not a 'p'
If the 1st char is not a 'l'
Prints "Rr"
Else
Prints "Rrrr"
Else:
Prints "-"
*/
printf(**a&6?**a&1?"Rr":"Rrrr":"-");
}
JavaScript, 70 63 bytes
2 bytes saved thanks to Luke
a=>a.replace(/./g,a=>[['Rr','rr','-',' - ']['onp '.search(a)]])
Vim (52 bytes)
:s/long/Rrrr/ge|s/short/Rr/ge|s/pause/-/ge|s/ / - /genter
Can probably be made shorter...
Python 3, 66 bytes
' - '.join(['Rrrr','-','Rr'][ord(s[1])%3]for s in input().split())
Sed, 50 bytes
Takes input from stdin, prints to stdout
s/l\w*/Rrrr -/g
s/s\w*/Rr -/g
s/p\w*/- -/g
s/ -$//
Edit - saved 2 bytes
Sed, 40 bytes
Copying idea from Nitrodon's answer
s/[srtaue]//g
y/lhongp/RRrrr-/
s/ / - /g
Edit: saved another 2 bytes
Batch, 88 bytes
@set/ps=
@set s=%s: = - %
@set s=%s:long=Rrrr%
@set s=%s:short=Rr%
@echo %s:pause=-%
Takes input on STDIN. Unfortunately loop overhead costs 26 bytes so this is just boring replacements.
Alice, 37 bytes
/ lRnrhR
\""orgrp-""!yi'."?-e"ySNo?@/
Explanation
This program makes the following substitutions:
l,h→Ro,n,g→rp→-- Space → Space
- Everything else → Nothing
"longhp "!i.?eyN?"RrrrR- "y' " - "So@
"longhp " Push this string
! Immediately move to tape
i Take input string
. Duplicate
?ey Remove all instances of the characters "longhp " from copy
N Remove the remaining characters from the original, leaving only "longhp "
?"RrrrR- "y Replace the characters in "longhp " with the corresponding characters in "RrrrR- "
' " - "S Replace all spaces with " - "
o Output
@ Terminate
AutoIt, 145 bytes
EXECUTE(STRINGREPLACE('MSGBOX(0,0,STRINGSTRIPWS(====INPUTBOX(0,0),"PAUSE",""),"LONG","Rrrr"),"SHORT","Rr")," "," - "),4))',"=","STRINGREPLACE("))
(AutoIt is really bad choice for code golf, tried my best to make it small as possible)
Haskell, 71 66 59 bytes
g 'o'="Rr"
g 'n'="rr"
g 'p'="-"
g ' '=" - "
g _=""
f=(g=<<)
Oh right, =<< is concatMap.
Takes advantage of the fact that "long" and "short" both have the letter o.
Ruby, 78 bytes
p ARGV[0].chars.map{|c|{p:'-',o:'Rr',g:'rr',' '.to_sym=>' - '}[c.to_sym]}.join
The only important parts of the input are p, o, g, and space... ignore the rest.
shortbecomesolongbecomesogpausebecomesp
Ruby, 67 bytes
p ARGV[0].split(' ').map{|w|w<'m'?'Rrrr':w<'q'?'-':'Rr'}.join ' - '
This is Johan Karlsson's JavaScript solution ported to Ruby. If you like this answer, you should upvote Johan's answer.
The key idea is to compare the word strings 'short', etc. to a single character in order to distinguish between words.
| Word | < 'm' | < 'q' | Output |
|-------|-------|-------|--------|
| short | false | false | 'Rr' |
| long | true | N/A | 'Rrrr' |
| pause | false | true | '-' |
Or, in alphabetical order:
- long
- m
- pause
- q
- short
Pyke, 22 20 bytes
cFh.o6.&\R*\-|l4)J" -
c - split(input, " ")
Fh.o6.&\R*\-|l4) - for i in ^:
h - ^[0]
.o - ord(^)
6.& - ^ & 6
\R* - ^
\-| - ^ or "-"
l4 - ^.title()
J" - - " - ".join(^)
The crux of this answer is the transformation of ["long", "short", "pause"] into [4, 2, 0]. It gets the code point of the first letter of each word and ANDs it with 6. By lucky coincidence it transforms to the values we're looking for. (I searched through quite a few other longer solutions before finding this one). Once that's done, we can further transform that list of ints into ["RRRR", "RR", ""] by multiplying our int by "R" which then turns into ["RRRR", "RR", "-"] and finally title casing it to get ["Rrrr", "Rr", "-"]. We then join the resulting list by " - "
SOGL V0.12, 28 bytes
θ{K;⁄5κ« r*; p=?X┌}}¹" - ”∑ū
fun fact: if it was allowed to delimit with - or - it'd be a byte shorter
Paradoc (v0.2.10), 21 bytes (CP-1252)
Wμ‹6&'r\°"-":Ãu}« rTc
Takes a string on the stack and results in a string on the stack. Prepend i to turn into a full program that reads from STDIN.
Uses &6 like the Pyke answer and everybody else, but joins the tokens together slightly differently, by adding a "-" token after each noise, deleting the last one, and then joining these tokens by spaces. Seems to save a byte over joining by " - ".
Explanation:
W .. Break into words
μ } .. Map over this block:
‹ .. Take the first character
6& .. Binary AND with 6, to get 4, 2, or 0
'r .. Character "r"
\ .. Swap top two of stack
° .. Replicate, to get "rrrr", "rr", or ""
"-" .. Push string "-"
: .. Duplicate on stack
à .. Compute the max...
u .. ... underneath the top of the stack (so, of the
.. second and third elements on the stack, i.e. the
.. string of "r"s and "-")
.. The mappped block ends here; we now have
.. something like ["rrrr", "-", "-", "-", "rr", "-"]
« .. Take all but the last
r .. Join with spaces (this built-in's name is two
.. characters, the first of which is a space)
Tc .. Title-case
v0.2.11 will support shaving two more bytes by replacing \° with x and "-" with '-.
Retina, 31 29 bytes
1 byte saved thanks to Dom Hastings
1 byte saved thanks to Neil
[^lhp ]
l
hrr
h
Rr
p
-
-
This is different approach than @DomHastings's answer.
Röda, 73 57 47 46 40 44 bytes
f&a{a~=*`s\w+|l;Rr;ong;rr;p\w+;-; ; - `/";"}
+4 bytes due to rule change (must use Rrrr instead of any 4 letter variant).
Previous code:
{[[split()|["Bzzz"]if[_="long"]else["Bz"]if[_1="short"]else["-"]]&" - "]}
Python 2, 69 bytes
lambda s:" - ".join((ord(i[0])&6)*"R"or"-"for i in s.split()).title()
Port of my Pyke answer
Excel, 100 bytes
=REPLACE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"long","- Bzzz"),"short","- Bz"),"pause","- -"),1,2,"")
Per examples, Input is SPACE separated string, as is output.
Question itself does not mention a SPACE requirement, allowing for a slightly shorter 97 byte solution:
=REPLACE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A1,"long","-Bzzz"),"short","-Bz"),"pause","--"),1,1,"")
Python 2, 76 69 64 bytes
lambda s:' - '.join('Rrrr'[:ord(b[0])&6]or'-'for b in s.split())
Alternates:
Python 2, 76 69 bytes
lambda s:' - '.join(['Rrrr','-','Rr'][ord(b[1])%3]for b in s.split())
Python 2, 69 bytes
lambda s:' - '.join('-Rrrr'['o'in b:8-ord(b[1])%9]for b in s.split())
PHP, 113 bytes
<?$s=[];for($i=1;$i<$argc;$i++){$c=$argv[$i][0];$s[]=($c<'m')?'Rrrr':(($c<'q')?'-':'Rr');}echo implode(' - ',$s);
First attempt at code golf, so probably a lot of optimisations available!
05AB1E, 33 27 25 21 bytes
#εÇн6&'m×™'-)éθ}… - ý
Explanation
# # split input on spaces
ε } # apply to each
Çн # get the character code of the head
6& # AND with 6
'm× # repeat "m" this many times
™ # title case
'-) # wrap in a list with "-"
éθ # get the longest string
… - ý # join to string using " - " as separator
Saved 3 bytes using the AND 6 trick from muddyfish's pyke answer
JavaScript (ES6), 65 59 bytes
s=>s.split` `.map(x=>x<'m'?'Rrrr':x<'q'?'-':'Rr').join` - `
let f =
s=>s.split` `.map(x=>x<'m'?'Rrrr':x<'q'?'-':'Rr').join` - `
console.log(f("long long short long short")); // => Rrrr - Rrrr - Rr - Rrrr - Rr
console.log(f("long long long short short short")); // => Rrrr - Rrrr - Rrrr - Rr - Rr - Rr
console.log(f("short short short pause short short short")); // => Rr - Rr - Rr - - - Rr - Rr - Rr
console.log(f("long short short long long pause short short")); // => Rrrr - Rr - Rr - Rrrr - Rrrr - - - Rr - Rr
R, 72 bytes
Takes input from stdin, prints to stdout.
cat(sapply(scan(,''),switch,long="vvvv",short="vv",pause="-"),sep=" - ")
Mathematica, 81 bytes
StringReplace[#,{"long"->"Bzzz -","short"->"Bz -","pause"->"- -"}]~StringDrop~-2&
R, 77 bytes
cat(c('Rrrr','Rr','-')[match(scan(,''),c('long','short','pause'))],sep=' - ')
Takes input through STDIN, checks whether the input matches long, short or pause and swaps the matches for Rrrr, Rr or - respectively.
This is then printed with - padded with spaces as separator, matching the desired output.