31
1
Introduction
We -- especially the geeks among us, who tend to be fans -- all remember this old Far Side cartoon:
Clearly, Professor Schwartzman could have brushed up on his programming skills just a wee bit more before he put his invention to use. But can you replicate it yourself... using as few bytes as possible?
Input Specs
You must create a script that translates dog sounds into appropriately intonated "Hey"s. This is pure code golf; the lowest number of bytes wins.
Your input will consist of some combination of the following tokens:
Bark
,Baark
,Baaark
,Baaaark
, ... (that is,B*rk
with at least 1a
replacing the asterisk)Woof
,Wooof
,Woooof
, ... (W*f
with at least 2o
s replacing the asterisk)Grr
,Grrr
,Grrrr
, ..., (G
followed by at least 2r
s)- Any number of
.
(period),!
(exclamation mark) and/or?
(question mark) characters, which may occur anywhere in the input
Note, again, that the Woof
-based and Grr
-based tokens always require at least two o
s and r
s respectively; Wof
and Gr
are not valid tokens.
There is no limit on how long a token can be (e.g., how many repeated a
s there can be in a Bark
token); however, your decoder only needs to work correctly for input tokens with up to 10 total a
s, o
s, or r
s to pass this challenge.
Output Specs
Faithful to Schwartzman's design, your canine decoder program must process it into output text as follows:
Bark
,Woof
, andGrr
becomeHey
;Baark
,Wooof
, andGrrr
becomeHeyy
;Baaark
,Woooof
, andGrrrr
becomeHeyyy
; etc.- For all
Bark
-based tokens, the number ofy
s in the outputHey
-based token must be equal to the number ofa
s; - For all
Woof
-based tokens, the number ofy
s in the outputHey
-based token must be one less than the number ofo
s; - For all
Grr
-based tokens, the number ofy
s in the outputHey
-based token must be one less than the number ofr
s; - All punctuation (
.
,!
, and?
) is left unchanged.
Remember to drop one y
from the output for Woof
s and Grr
s only! The input Baaaaaaaark?
, with 8 a
s, will become Heyyyyyyyy?
, with a matching set of 8 y
s. However, Woooooooof?
becomes only Heyyyyyyy?
, with 7 y
s.
Again, if you can get your program to work for input tokens of unlimited size, that's great, but for purposes of this challenge, your program will only be checked to ensure that it works properly for input tokens that have no more than 10 repeated letters.
All Bark
-, Woof
-, and Grr
-based tokens in your input are assumed to begin with capital letters. Therefore, there is no need to handle turning Bark grrr
into Hey heyy
or anything similar.
Example Inputs and Outputs
- Input:
Bark. Bark! Bark!!
- Output:
Hey. Hey! Hey!!
- Input:
- Input:
Baaaaaark?
(sixa
s) - Output:
Heyyyyyy?
(sixy
s)
- Input:
- Input:
Grrrrrrrr...
(eightr
s) - Output:
Heyyyyyyy...
(seveny
s)
- Input:
- Input:
?...!
- Output:
?...!
- Input:
- Input:
Wooof Woof? Grrrr. Baaaark Grr!
- Output:
Heyy Hey? Heyyy. Heyyyy Hey!
- Input:
10Hi, and welcome to the site! Just so you know, it is customary on this site to wait a while before accepting the shortest answer. I'd encourage you to unaccept the answer you have accepted, and wait until activity on this question dies down before accepting the shortest answer. This will also encourage more answers. – James – 2016-06-27T05:28:36.367
Related. – Martin Ender – 2016-06-27T09:35:00.407
Thanks for the tips regarding the acceptance process. I was actually planning to check the list of answers every few hours and, if I noticed that a better answer had come along, accept it. Sorry for anyone that I may have denied reputation to here. – A. Mirabeau – 2016-06-27T12:18:18.793
5@A.Mirabeau That's honourable and how it would work ideally, but some people aren't that attentive, so most answerers might assume that the winner has already been chosen. While there's nothing wrong with choosing a winner right away if you're planning to update it, you're likely going to get fewer answers because of it along with some complaints, so it's usually better to wait at least a week. – Martin Ender – 2016-06-27T12:40:20.840