18
\$\begingroup\$

(Meaning: Convert English to Bleet)

We have praised goats as god for years now.

But if we can't translate English to 'Bleet', the Goat God's language, we cannot communicate with them.

So, to communicate with them, we have researched the activities of goats, and retrieved this pattern, which is the core of the language.

Say 'Bleet' for the length of each words. That means the amount of 'e's should be (length-3) for words longer than 3 letters.You shall cut down 'Bleet' for words shorter than 'Blt'. For example, 'be' becomes 'bl', but 'cat' and 'boat' becomes 'blt' and 'blet'.

As it seems, they don't actually change non-alphabet characters to 'Bleet'. Our research showed that 'Hello, World!' to Bleet is 'Bleet, Bleet!' not 'Bleeet Bleeet'. Also, The goats are not so intelligent(no offense), so they don't seem to understand non-ascii characters or diacritics at all.

Now, It's time to make a translator to communicate with the goat gods.

Bleeeeet (Meaning: Examples)

Hello, World! => Bleet, Bleet!
lorem ipsum dolor sit amet. => Bleet Bleet Bleet Blt Blet.
We praise the Goat God! => Bl Bleeet Blt Blet Blt!
I have a pen => B Blet B Blt
0123456789_ => 0123456789_
0te_st1 => 0Bl_Bl1
\$\endgroup\$
  • 1
    \$\begingroup\$ Related! \$\endgroup\$ – Jonathan Allan Mar 10 '17 at 15:01
  • 1
    \$\begingroup\$ And what about words containing apostrophes? Will it's become Blt or Bl't or Bl'B? \$\endgroup\$ – Kevin Cruijssen Mar 10 '17 at 16:05
  • 3
    \$\begingroup\$ It's up to you, but if you keep it I'd notify every answerer. If it were me I think I'd probably allow any behaviour: pass them (Jimmy's:Bleee't), treat them as word separations (Jimmy's:Bleet'B), or treat them as part of words (Jimmy's:Bleeeet). If I had to choose one I'd go with the word separator option, since it's what the 6 answers do. \$\endgroup\$ – Jonathan Allan Mar 10 '17 at 16:18
  • 2
    \$\begingroup\$ This is really good challenge, we should have more like this. \$\endgroup\$ – Downgoat Mar 14 '17 at 16:04
  • 2
    \$\begingroup\$ @Downgoat quality-wise, or goat-wise? \$\endgroup\$ – Matthew Roh Mar 14 '17 at 16:52

14 Answers 14

13
\$\begingroup\$

Retina, 31 bytes

T`lL`e
(?<!e)e
B
Be
Bl
e(?!e)
t

Try it online!

Explanation

T`lL`e

Turn all letters into es.

(?<!e)e
B

Turn the first e in each run into B.

Be
Bl

Turn Be into Bl.

e(?!e)
t

Turn the last e in each run into t.

\$\endgroup\$
  • \$\begingroup\$ T1L the T stage "wraps" the translation pairs so that you can turn all letters like that to e \$\endgroup\$ – Conor O'Brien Mar 14 '17 at 1:07
  • \$\begingroup\$ @ConorO'Brien It's actually a lower-case l, not a 1, but I'm not sure what you mean by "wrap". Transliteration simply repeats the last character in the target pattern, so if it was T`lL`ef, you'd map a to e and all other letters to f, not alternatingly to e and f. \$\endgroup\$ – Martin Ender Mar 14 '17 at 8:10
  • \$\begingroup\$ it was a bad joke. Sorry \$\endgroup\$ – Conor O'Brien Mar 14 '17 at 16:15
4
\$\begingroup\$

JavaScript (ES6), 79 77 74 bytes

s=>s.replace(/[A-Z]+/gi,x=>x.replace(/./g,(_,i)=>'Bl'[i]||'et'[+!x[i+1]]))

Alternate approach, currently 83 78 bytes:

s=>s.replace(/[A-Z]+/gi,x=>`Bl${'e'.repeat((l=x.length)>3&&l-3)}t`.slice(0,l))

The best I could do recursively was 88 bytes:

f=([c,...s],i=0,q=/^[A-Z]/i)=>c?q.test(c)?('Bl'[i]||'te'[+q.test(s)])+f(s,i+1):c+f(s):''
\$\endgroup\$
  • \$\begingroup\$ I came up with 'Blet'[i>1?2+!x[i+1]:i] but sadly it's the same length. \$\endgroup\$ – Neil Mar 10 '17 at 18:25
  • \$\begingroup\$ @Neil Yeah, I figured it would be possible to do it that way, but I'm surprised it was nearly shorter than the way I'm doing it. \$\endgroup\$ – ETHproductions Mar 10 '17 at 18:29
4
\$\begingroup\$

PHP, 115 88 86 77 75 bytes

preg_replace with arrays (requires PHP 5.4 or later)

echo preg_replace(["#[a-z]#i","#(?<!e)e#",_Be_,"#e(?!e)#"],[e,B,Bl,t],$argn);

Run with echo '<string>' | php -nR '<code>' or test it online.

breakdown

SEARCH      EXPLANATION             REPLACE     EXAMPLE
            original string                     Hello
[a-z]       every letter            e           eeeee
(?<!e)e     first letter            B           Beeee
Be          first two letters       Bl          Bleee
e(?!e)      last letter if still e  t           Bleet

Revision 5: saved 9 bytes with Martin Ender´s regex chain.
(That also fixed cases with non-alphabetic word characters = digits/underscores.)

\$\endgroup\$
3
\$\begingroup\$

Haskell, 135 128 bytes

b"e"="B"
b"ee"="Bl"
b('e':_:_:e)="Bl"++e++"t"
b e=e
e!(l:t)|elem l$['a'..'z']++['A'..'Z']=('e':e)!t|1<3=b e++l:""!t
e!_=[]
(""!)

Try it online! Usage (""!) $ "some string". Without regexes, this turned out to be quite long, maybe some other approach is shorter. Edit: Saved 7 bytes thanks to @nimi!

\$\endgroup\$
  • 1
    \$\begingroup\$ Renaming function b to a you can apply it immediately when constructing the resulting string and omit the final =<<: b!(l:t)|...|1<3=a b++l:""!t;b!_=a b;(""!). \$\endgroup\$ – nimi Mar 10 '17 at 17:30
  • \$\begingroup\$ Doesn't work online for It's Jimmy's test I get Bl'B Bleet'B \$\endgroup\$ – cleblanc Mar 10 '17 at 20:14
  • \$\begingroup\$ @cleblanc This requirement was added after my answer and invalidates most of the current answers ... let me ask the OP. \$\endgroup\$ – Laikoni Mar 10 '17 at 20:45
  • \$\begingroup\$ @Laikoni Right. I came late to this game and the apostrophe is a particularly difficult exception to handle. \$\endgroup\$ – cleblanc Mar 10 '17 at 20:53
2
\$\begingroup\$

Perl 5, 47 bytes

Saved 15 bytes by using the same technique as Martin Ender's Retina answer. (This answer is basically a port of his answer now)

46 bytes of code + -p flag.

s/\pl/e/g;s/(?<!e)e/B/g;s/Be/Bl/g;s/e(?!e)/t/g

Try it online!


Older versions: 62 bytes:

s/\pl+/$l=length$&;$_=Bl.e x($l-3).t;chop while$l<y%%%c;$_/ge

And 68 bytes:

s%\pl+%$_=$&;s/./B/;s/.\K./l/;s/(?<=..).(?=.)/e/g;s/..\K.$/t/;$_%ge
\$\endgroup\$
2
\$\begingroup\$

PHP, 84 Bytes

<?=preg_replace(["#[a-z]#i","#(?<!l)l#","#(?<=l)l#","#e(?!e)#"],[l,B,e,t],$argv[1]);

PHP, 117 Bytes

<?=preg_replace_callback("#[a-z]+#i",function($m){return substr(str_pad(Bl,-1+$l=strlen($m[0]),e).t,0,$l);},$argv[1]);
\$\endgroup\$
  • \$\begingroup\$ Save one byte with -1+$l=... \$\endgroup\$ – Titus Mar 10 '17 at 14:31
  • \$\begingroup\$ @Titus nice and I Have found a better solution \$\endgroup\$ – Jörg Hülsermann Mar 10 '17 at 15:25
  • 1
    \$\begingroup\$ Zwei Dumme - ein Gedanke. :) But \bl fails for non-alphabetic word characters: _we_. You need an explicit assertion: (?<!l)l. Same for e\b -> e(?!e) (+7 bytes) \$\endgroup\$ – Titus Mar 10 '17 at 15:26
  • \$\begingroup\$ @Titus In the meantime it is myself noticed that my thought was wrong. And I love your german comment. \$\endgroup\$ – Jörg Hülsermann Mar 10 '17 at 15:43
2
\$\begingroup\$

C, 120 151 140 111 108 105 104 92 90 Bytes

Working for "It's Jimmy's test" --> Bl'B Bleet'B Blet

j;f(char*m){for(;*m=!isalpha(*m++)?j=0,*(m-1):"*Blet"[isalpha(*m)?j^3?++j:j:j>1?4:++j];);}

The output is now a side effect by destroying the original string.

main(c,v)char**v;{
    char test[] = "The End is near Fellows!";
    f(test);puts(test);
    char test2[] = "We praise the Goat God!";
    f(test2);puts(test2);
    char test3[] = "It's Jimmy's test";
    f(test3);puts(test3);
    char test4[] = "0te_st1";
    f(test4);puts(test4);
    char test5[] = "I have a pen";
    f(test5);puts(test5);
    char test6[] = "_0123456789_";
    f(test6);puts(test6);
}

I think it's correct at least now

Blt Blt Bl Blet Bleeeet!
Bl Bleeet Blt Blet Blt!
Bl'B Bleet'B Blet
0Bl_Bl1
B Blet B Blt
_012345678_
\$\endgroup\$
  • \$\begingroup\$ Jimmy? \$\endgroup\$ – DLosc Mar 13 '17 at 20:57
  • \$\begingroup\$ @DLosc I haven't gone mad and died yet. \$\endgroup\$ – cleblanc Mar 13 '17 at 21:06
2
\$\begingroup\$

Python 2.7, 129 118 114 109 95 91 88 bytes

import re
s=re.sub
def f(i):print s(r"e\b","t",s("Be","Bl",s(r"\be","B",s("\w","e",i))))

Just an re.sub chain

Step by step

Example input: "We praise the Goat God!"


Alias sub so we can save bytes on repeated calls

import re
s=re.sub

Replace all word characters with "e"

s("\w","e",i)

Output: ee eeeeee eee eeee eee!

Replace all "e"s which are preceded by a word boundary (Beginning of word) with "B"

s(r"\be","B",s("\w","e",i))

Output: Be Beeeee Bee Beee Bee!

Replace all "Be" with "Bl"

s("Be","Bl",s(r"\be","B",s("\w","e",i)))

Output: Bl Bleeee Ble Blee Ble!

Replace all "e"s which are followed by a word boundary with "t"

s(r"e\b","t",s("Be","Bl",s(r"\be","B",s("\w","e",i))))

Output: Bl Bleeet Blt Blet Blt!

\$\endgroup\$
  • \$\begingroup\$ Welcome to PPCG! We allow functions to print their results, so replacing return with print should save a byte. \$\endgroup\$ – Conor O'Brien Mar 14 '17 at 1:43
  • \$\begingroup\$ You can also remove the leading r from raw strings if they have no backlashes in them saving another 3 bytes \$\endgroup\$ – Conor O'Brien Mar 14 '17 at 2:45
  • \$\begingroup\$ Thanks @ConorO'Brien ! I was able to simplify a piece of the regex (which ended up needing an r) and I got it down to 95 bytes. Thanks for the suggestion! \$\endgroup\$ – Brandon Sturgeon Mar 14 '17 at 19:10
  • \$\begingroup\$ Alright I got it down to 88 bytes and I think that's the best I can do here \$\endgroup\$ – Brandon Sturgeon Mar 14 '17 at 19:21
1
\$\begingroup\$

Pip, 28 bytes

aR+XA{Y'eX#a-3\"Bl\yt\"@<#a}

Takes input as a command-line argument. Try it online!

Explanation

This was fun--I got to use regex modifiers and string interpolation.

                              a is 1st cmdline arg; XA is the regex `[A-Za-z]` (implicit)
aR                            In a, replace
   XA                          the regex XA
  +                            wrapped in (?:  )+
     {                     }  with this callback function:
          #a-3                 Length of argument - 3
       'eX                     Repeat e that many times (empty string if #a-3 is negative)
      Y                        Yank that string into the y variable
              \"Bl\yt\"        An escaped string, which interpolates the value of y
                       @<#a    Take first len(a) characters
                              After the replacement, the string is autoprinted
\$\endgroup\$
1
\$\begingroup\$

Python 3, 271 bytes

I am aware that this is rather long and I welcome suggestions on how to reduce the length.

def f(s):
 b=[];t='';f=[];a=list.append
 for c in s:
  if c.isalpha():t+='e'
  else:
   if t:a(b,t);t=''
    a(b,c)
 if t:a(b,t)
 for i in b:
  i=[*i]
  if i[0]=='e':
   i[0]='B';i[-1]=[i[-1],'t'][len(i)>2]
   if len(i)>2:i[1]='l'
  a(f,''.join(i))
 return ''.join(f)
\$\endgroup\$
  • \$\begingroup\$ Welcome to the site! I see a couple golfs you could make. You can visit our tips page for a list of useful tips for golfing in Python. \$\endgroup\$ – Wheat Wizard Mar 11 '17 at 16:44
  • \$\begingroup\$ instead of x.append(y) or in your case, a(x,y), you can do x+=y, (comma required) \$\endgroup\$ – Cyoce Mar 14 '17 at 20:33
1
\$\begingroup\$

stacked, 57 bytes

'\l+'{!n size 2-:4\^5*1+3/\1<-4 tb 0\,'Blet'\#''join}repl

Try it online! Takes input from the top of the stack.

Let a(n) = A136412(n - 2) = (5 × 4n − 2 + 1) ÷ 3. Converting a(n) to base 4 yields:

a(3) = 134
a(4) = 1234
a(5) = 12234
a(6) = 122234
...

Mapping indices 0..3 to the string Blet, we get:

a(3) = lt
a(4) = let
a(5) = leet
a(6) = leeet
...

Now, prepending B gives us the desired string, given the length. Mostly. One just needs to handle the special cases for n ≤ 2. In my case, this is solved by subtracting (n − 2 < 1) as a numeric boolean (1 for "true" and 0 for "false").

As for the specifics of the answer:

'\l+'{! ... }repl
             repl    replace all
'\l+'                alphanumeric strings ("letters")
     {!     }        applying this function to the result.
\$\endgroup\$
1
\$\begingroup\$

Python 2, 137 114 bytes

def f(s,r='',l=-3):
 for c in s+'\0':
	if c.isalpha():l+=1
	else:r+=('Bl%st'%('e'*l))[:l+3*(l>=0)]+c;l=-3
 print r

Try it online!

\$\endgroup\$
0
\$\begingroup\$

Java 7, 201 bytes

String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}

Not really happy with it, and can certainly be golfed some more..

Explanation:

String c(String s){               // Method with String parameter and String return-type
  String r="",                    //  The return-String
         z="e([^e]|$)";           //  Partial regex String that's used twice ('e' followed by non-'e' or nothing)
  char p=0;                       //  The previous character
  int x;                          //  Another temp value
  for(char c : s.toCharArray()){  //  Loop over the characters of the input String
    x = c&~32;                    //   Make every lowercase character uppercase (this returns an integer, hence the integer temp value, which is shorter than a cast to char)
    p = x>64 & x<91 ?             //   If the current character is a letter:
         p == 66 ?                //    And if the previous character is 'B':
          'l'                     //     Set the character value to 'l'
         : p>100&p<109 ?          //    Else if the previous character is either an 'e' or 'l':
            'e'                   //     Set the character value to 'e'
           :                      //    Else:
            66                    //     Set the character value to 'B'
         :                        //   Else (not a letter):
          c;                      //    Set the character to the current character
    r += p;                       //   Append the result-String with this character
  }                               //  End loop
  return r                        //  Return the result-String
    .replaceAll("l"+z,"lt$1")     //   After we've replaced all occurrences of "le." with "lt." (where "." can be anything else, including nothing at the end of a line)
    .replaceAll(z,"et$1")         //   And also replaced all occurrences of "ee." with "et." (where "." can again be anything else)
}                                 // End of method

Test code:

Try it here.

class M{
  static String c(String s){String r="",z="e([^e]|$)";char p=0;int x;for(char c:s.toCharArray()){x=c&~32;p=x>64&x<91?p==66?'l':p>100&p<109?'e':66:c;r+=p;}return r.replaceAll("l"+z,"lt$1").replaceAll(z,"et$1");}

  public static void main(String[] a){
    System.out.println(c("Hello, World!"));
    System.out.println(c("lorem ipsum dolor sit amet."));
    System.out.println(c("We praise the Goat God!"));
    System.out.println(c("I have a pen"));
    System.out.println(c("0123456789_"));
    System.out.println(c("0te_st1"));
  }
}

Output:

Bleeet, Bleeet!
Bleeet Bleeet Bleeet Blt Bleet.
Bl Bleeeet Blt Bleet Blt!
B Bleet B Blt
0123456789_
0Bl_Bl1
\$\endgroup\$
  • \$\begingroup\$ s.split("") instead of s.toCharArray() saves some I believe \$\endgroup\$ – Kritixi Lithos Mar 11 '17 at 10:33
  • \$\begingroup\$ @KritixiLithos I tried it, but then I have the issue of checking if the String is a letter (x=c&~32 won't work on a String, and x>64&x<91 both won't work anymore). If you can make it shorter with the split let me know, though. \$\endgroup\$ – Kevin Cruijssen Mar 11 '17 at 11:46
0
\$\begingroup\$

05AB1E, 36 bytes

lDAsSå.¡€g£vyAySåPigÍ<'e×"Blÿt"yg£}J

Try it online! or as a Test suite

Explanation

Prepare input:

lD                                    # convert input to lower-case and duplicate
  As                                  # push lower-case alphabet and swap input to the top
    Så                                # check each char in input for 
                                      # membership in the alphabet
      .¡                              # split into chunks of equal elements
        €g                            # get length of each chunk
          £                           # split input into chunks of those lengths

This creates a list such as ['hello', ', ', 'world', '!'] for the input Hello, World!

Iterate over list:

v                          # for each element in the list
 y                         # push current element
  AySåPi               }   # if all members of current element are letters
        gÍ<'e×             # repeat string "e" len(element)-3 times
              "Blÿt"       # replace "ÿ" with the e's in the string "Blÿt"
                    yg£    # take the first len(element) chars of the string
                        J  # join to string
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.