Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given an input of a program written in oOo CODE, output the BF code that it represents.

Here is a short description of how oOo CODE works:

  • First, all non-alphabetic characters are removed (everything not in the range A-Za-z).

    For example, take the program PROgRam reVERsES giVeN iNPut sEqUENcE (an example given on the esolangs wiki page that does exactly what you'd expect). After this first step, we now have PROgRamreVERsESgiVeNiNPutsEqUENcE.

  • Next, divide all remaining characters into groups of 3. We now have PRO,gRa,mre,VER,sES,giV,eNi,NPu,tsE,qUE,NcE. If there is a trailing group of 1 or 2 characters, discard it.

  • Convert each group of 3 letters into a BF command based on the following table:

    ooo  >
    ooO  <
    oOo  [
    oOO  ]
    Ooo  -
    OoO  +
    OOo  .
    OOO  ,
    

    That is, if the first letter of a group is lowercase, the second is uppercase, and the third is lowercase, it would translate to the command [.

    With our example, this finally becomes the BF program ,[>,]<[.<]+, which does indeed reverse its input.

Since this is , the shortest code in bytes will win.

Test cases:

<empty string> -> <empty string>
A -> <empty string>
Ab -> <empty string>
Abc -> -
AbcD -> -
AbcDe -> -
AbcDef -> --
1A_b%c*D[]e\\\f! -> --
PROgRamreVERsESgiVeNiNPutsEqUENcE -> ,[>,]<[.<]+
share|improve this question
20  
I'm waiting for somebody with an answer in oOo ... – Glorfindel Feb 28 at 19:17
13  
@Glorfindel: Happy to oblige. – nneonneo Feb 29 at 2:20

23 Answers 23

oOo, 1569 1515 bytes

Had to be done. Try it here.

Golfed:

oooooooooOoOoooooooooooooooOoOooooooOOOoOoooooooOoOOoOOoOOoOOoOOoOOoOOoOoOoooOOoOOoOOoOOoOOoOOoOOoOOoOoooOoooOOooOOoOooOoOoOoooooOoooOoooooOOooOooOoOOooOoOoOoooooOoOooooOoOoooooOoOooOoOOoooOoOooooooOoOOoOOoOOoOOoOoOoooOOoOOoOOoOOoOOoOoooOoooOOooOOoOOoOooOoOoOoooooOoooOoooooOOooOooOoOOooOoOoOoooooOoOooooOoOoooooOoOooOoOOoooOoOoooOoOOoOOoOOoOOoOOoOOoOooOoOoOoooooOoooOoooooOOooOooOoOOooOoOoOoooooOoOooooOoOoooooOoOooOoOOoooOoOooooooOoOOoOOoOOoOOoOoOoooOOoOOoOOoOOoOOoOoooOoooOOooOOoOOoOooOoOoOoooooOoooOoooooOOooOooOoOOooOoOoOoooooooooOoOoooOOooOooOoOOooOoOoOooooOooOooOooOooOooOooOooOooOooOooOOoOoooooooooooooooooooooooooooooooooooooooooooOoOoooOOooOooOooOooOoOOoOOooOoOoOooooooooooooOoOoooOOooOooOooOooOoOOoOOooOoOoOooooOooOooOooOooOooOooOooOooOOoOooooooooooooOoOoooooooooooooooooooooooooOoOoooOOooOooOooOooOoOOoOOooOoOoOooooooooooooOoOoooOOooOooOooOooOoOOooOooOooOooOooOooOooOoOoooooOooooooooooooooooOoOOoOOoOOoOOoOOoOoOoooOOoOOoOOoOOoOOoOOoOOoOoooOoooOOooOOoOOoOooOooOooOoOoooooOoooooOoooOOoooooOoooOOooOoOoooooooOoOOoOooOooOOoooOOooOOooooooOOooOoOooooOoOooooOooooOooooOooOOoooooOoooOOooOoOoooooooOoOooOooOOoooOOooOOoooOOooOOooooooOOooOoOooooOoOooooooooooooOoOOoOOoOOoOoOoooOOoOOoOOoOOoOoooOoooOOooOooOooOoOooooooooooOoOOoOOoOOoOOoOoOoooOOoOOoOOoOOoOOoOOoOoooOoooOOooOOoOooOoOooooOoOOoOooOooOOoooooOoooOOooOoOoOoooOOooOOooooooOOooOoOooooOoOooooOoooOOoooooOoooOOooOoOoooooooOoOOoOooOooOOoooOOooOOoooOOooOOoooOOOoOooooooooooooOOooOoOoooOOooOooOooOooOooOOooooOOooooOOoooOOoOOooooooooooooooooooooooooOoOooooooOOOoOO

Translated to Brainfuck (with linebreaks for clarity):

>>>+>>>>>+>>,[>>++++++++[<++++++++>-]<+<[->-[>]<<]<[->+>[->+<]>+>>+++++[<+++++>-
]<++<[->-[>]<<]<[->+>[->+<]>+>+++++++<[->-[>]<<]<[->+>[->+<]>+>>+++++[<+++++>-]<
++<[->-[>]<<]<[->>[-]<<]<[-<<<<<<<<<<<+>>>>>>>>>>>>>>[-]<<<<]]<[->>>[-]<<<<]]<[-
<<<<<<<<<+>>>>+>>>>>>>>[-]<<<<]]<[->>>[-]<<<<]<<<<<<<[>[>>>>>++++++[<+++++++>-]<
++<<<[>[>[<->-]<[>>++<<-]<->]<[>+>[>-<<->-]<[>>+<<-]<-]<->]<[>+>>>>++++[<++++>-]
<<<[>>>+++++[<++++++>-]<+<[>++<<->-]<[-]<->]<[>+>[<->-]<[>>++<<-]<-]<-]+>>>>.[-]
<<<<<-<-<-]]>>>>>>>>+>>,]

Ungolfed with explanation:

this progrAm Translates ooo codE tO brainfUCK cOde. i guesS sINcE ThE ExAMpLE
tEXt WAs SeLf-doCUmENtINg, I ShOUlD PrOBaBLy Make This SElf-DOcUmeNtInG too.

oh, I shoUld menTIon ThaT i WRotE tHe OriginAl BrainFuCk code EnTirElY By haNd.
If you waNt TO sEE tHE bRAiNfUck cODe, RUn THiS PrOGrAm wiTh itSElf AS iNPuT!

baSiCaLly, thiS proGram seTS up MemOrY As fOlLoWs: the fIrSt thrEe Bytes aRe
"ValId" FLags (V0, v1, V2), theN tHErE'S a BArRIeR (A 1) fOLlOweD bY tHree
"vaLue" bIts (b0, b1, b2). THe rEst Of THe aRrAy Is basiCaLly juSt ScratcH
sPacE. tO Save SpAce, i'm slIdINg THe POiNTeR fOrwaRD bY OnE In EAcH ItEratIon
uNTil THe POiNteR hItS the baRrieR, at whiCH poInt ThE ProGrAm Prints out tHe
ConvERteD chArACteR.

tHe ProgrAm eXteNsiVelY usEs tHe cLevEr "gReaTEr-Than" comparison operator
described by dheeraj ram aT
hTtp://sTAckOveRflOw.cOm/QUeSTioNs/6168584/BrAinfuck-comparE-2-nUmbeRS. i hAppEn
tO reAlLY lIKe tHiS iMplemEntAtiOn bEcaUse It iS boTh cOMpAct and nestablE,
wHich is critical for my bf code tO wOrk pROpeRly.

I seT up ThE ReQUisItE sTructure, then pErForm A BunCh oF neSteD cOMpaRisOns
ThaT loOk rOugHlY like tHis:

    if(in >= 65 /* capital a */) {
        if(In <= 90 /* CApITaL Z */) {
            vI = 1
            Bi = 1
        } ELsE {
            iF(in >= 97 /* lOWeRCaSE a */) {
                IF(iN <= 122 /* LoWErCAsE z */) {
                    vi = 1
                }
            }
        }
    }

At thE End OF tHEsE coMpaRisOnS, if the V (valid) Bit iS Set, the ProgRAm sTePs
the poiNtER rIghTwaRDs. if IT hiTS the barRIer, It Then gOeS into A big sEt of
nEstED condiTionALs tHaT test the AcCumUlaTEd vaLUe bITs, anD ConSTruct thE
CorReSpondInG character to pRiNT oUT. tHEn It ReseTS bACk TO tHE iNitiAl stATe.

fInaLly, It Reads anotheR iNPuT ChARaCTeR aNd goES bACk TO lOOpINg.

SO tHere You hAVe iT - An Ooo To BrainFuCK cOnvErtER writtEn in OOo (aNd
BrAinfUCk, bY ExtensiON!). siNcE i havE a Few moRe chARacterS to sPAre In This
progRaM, HeRe's A coUPle oF StrESs teST paTTernS:

0123456789ABcDefghijklmnopQRstUvWxyzABcdEfgHijKlmNopQRstuvWXyz!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ 
 ~}|{`_^]\[@?>=<;:/.-,+*)('&%$#"!zyXWvutSRqPOnmlkjihgfedcbazyxwvutsrqPoNmlkjihGFEdCBa9876543210

Thanks for the interesting challenge!

share|improve this answer
1  
oh god... This is epic! Good job. – Eᴀsᴛᴇʀʟʏ Iʀᴋ Feb 29 at 2:23
10  
... WOW. I am impressed. For the curious: goo.gl/vbh3h9 (the full Try it online link was too long for obvious reasons). – Doorknob Feb 29 at 2:23
1  
Golfed/optimized out a bunch of chars. New tryit link: goo.gl/ISjwLB – nneonneo Feb 29 at 2:45
6  
THIS IS THE BEST THING I HAVE EVER SEEN ON THIS SITE – Texenox Feb 29 at 10:03
11  
@Texenox In that case, welcome to Programming Puzzles and Code Golf! I'm sure you'll find many more answers around that'll contend for that "best thing I have ever seen" spot in your mind :) – Sp3000 Feb 29 at 10:16

CJam, 36 35 bytes

l{el_eu-},'_f<0+3/W<2fb"><[]-+.,"f=

Test it here.

Explanation

l               e# Read input.
{el_eu-},       e# Discard all characters that don't change in a lower/upper case
                e# transformation, i.e. non-letters.
'_f<            e# Compare with '_' to determine case as 0 or 1.
0+              e# Append a zero.
3/              e# Split into chunks of 3.
W<              e# Discard last chunk.
2fb             e# Convert each chunk from base 2.
",.+-][<>"f=    e# Select the corresponding character for each chunk.
share|improve this answer
    
Append a value and discard last chunk: clever! – Luis Mendo Feb 28 at 19:37
    
Ahh, that is really clever – Adnan Feb 28 at 21:47

JavaScript (ES6), 94 93 91 85 84 bytes

Saved 1 byte thanks to @dev-null

x=>x.replace(/[a-z]/gi,c=>(a+=+(c<'a'))[2]?b+="><[]-+.,"['0b'+a-(a="")]:0,a=b="")&&b

I've tried many variants of this, but this seems to be the shortest. Also works on empty input!

How it works

First, with x.replace(/[a-z]/gi,c=>, we find take each letter c in the input. We set a and b to "" at the other end of the function call, since the function ignores any parameters past the second. a will store a binary string for determining which character we are currently making, and b will store the result.

Now for the confusing part: first, with (a+=+(c<'a')), we append a 0 to a if c is uppercase; 1 otherwise. This expression returns the new value of a, so then we can check if it has reached three chars of length with by checking if the character at index 2 exists:[2]?. If not, we simply end the function with :0.

If a is now three chars in length, it is a binary number between 000 and 111. We can convert this to a decimal number by appending "0b" to the beginning, then forcing the engine to parse it as a number with '0b'+a-0.

However, we still need to reset a to the empty string. We can't just do '0b'+(a="")-0 because that would mean the string parsed is just 0b. Fortunately, when parsed as a number, the empty string becomes 0, so we can replace the 0 with (a="").

Now we have our number, and we can just append the character at that index in "><[]-+.," to b. After the replace is done, we use &&b to return it from the function. (Well, unless the result of .replace is empty, which only happens on empty input and returns the empty string anyway.)

share|improve this answer
    
Nice one byte save with: '0b'+a-0 vs +`0b${a}` and +("0b"+a) – andlrc Feb 28 at 22:53
    
So, replace wins after all! – Neil Feb 29 at 0:09
    
@Neil Yea sorry for leading you down the match trail ... – andlrc Feb 29 at 0:16
    
Latest version has problems with leading non-letters? – Neil Feb 29 at 1:43
    
@Neil You're right. Fortunately, I managed to golf a byte off of the working version using a trick from the non-working one. – ETHproductions Feb 29 at 1:51

MATL, 38 32 bytes

'><[]-+.,'jt3Y2m)3ZCtAZ)92<!XBQ)

Try it online!

'><[]-+.,'      % push string with BF commands
j               % read input as a string
t               % duplicate
3Y2             % predefined literal: string 'A...Za...z'
m               % true for elements of input string that are letters
)               % index into input string to keep only letters
3ZC             % 2D array whose columns are non-overlapping slices of length 3.
                % The last column is padded with zeros if needed
tA              % duplicate. True for columns that don't contain zeros 
Z)              % keep those columns only. This removes padded column, if any
92<             % 1 for upper case letters, 0 for lower case letters in the 2D array
!               % transpose so each group of 3 is a row
XBQ             % convert each row from binary to decimal and add 1
)               % index into string containing the BF commands. Implicitly display
share|improve this answer

05AB1E, 35 32 bytes

Code:

á0«3÷\)vyS).uïJC",.+-][<>"Sr@?)\

Using a very clever trick from Martin Büttner, from this answer. Explanation:

á0«                               # Remove all non-alphabetic characters and append a zero
   3÷\                            # Split into pieces of 3 and discard the last one
      )v                          # Wrap everything into an array and map over it
        yS).uï                    # Is uppercase? Converts AbC to [1, 0, 1]
              JC                  # Join and convert from binary to int
                ",.+-][<>"        # Push this string
                          S       # Split the string
                           r@     # Reverse the stack and get the character from that index
                             ?    # Pop and print without a newline
                              )\  # Wrap everything into an array and pop

Try it online!

Uses CP-1252 encoding.

share|improve this answer

Retina, 79 75 71 70 bytes

Thanks to randomra for saving 1 byte.

i`[^a-z]

M!`...
m`^
;
+`(.*);(.)
$1$1$2;
T`l
.+
$.&
T`d`_><[]\-+.,
¶

Try it online!

Explanation

i`[^a-z]

We start by removing everything that's not a letter.

M!`...

This splits the string into chunks of three characters by returning all (non-overlapping) 3-character matches. This automatically discard any incomplete trailing chunk.

m`^
;

Prepend a ; to each line. We'll use this as a marker for the base-2 conversion. Speaking of which, we'll simply treat upper-case letters as 1 and lower-case letters as 0.

+`(.*);(.)
$1$1$2;

This does a funny base-2 to unary conversion. At each step we simply double the characters left of the ; and move the ; one to the right. Why does this work? Remember we'll be interpreting lower case as 0 and upper case as 1. Whenever we process a letter, we simply double the running total (on the left) so far - double lower-case letters are just 2*0=0, so they can be completely ignored and upper-case letters represent the binary number so far, so doubling them is what we want. Then we add the current letter to that running total which represents 0 or 1 correspondingly.

T`l

Remove all lower-case letters/zeroes.

.+
$.&

Match each line and replace it with the (decimal) number of characters in that line. Due to the ; this turns the unary number into its decimal equivalent + 1.

T`d`_><[]\-+.,

Transliteration which substitutes 1-8 with the corresponding command.

Remove linefeeds.

share|improve this answer
    
That's a clever way to split into chunks of three chars. Have you used this before? – ETHproductions Feb 29 at 2:03
    
@ETHproductions I think I have but I'm not sure where. I might be thinking of codegolf.stackexchange.com/a/69518/8478 – Martin Ender Feb 29 at 7:12
    
70 bytes and a bit less shorter with my newly added Retina ideas. – randomra Mar 1 at 11:38
    
@randomra ah nice idea for the ;. I'll edit that in later. – Martin Ender Mar 1 at 12:15

Japt, 37 36 bytes

Uo"%l" f'.³ £",><[]-+."gX®c ¤gJÃn2Ãq

Test it online!

How it works

Uo"%l" f'.³ £  ",><[]-+."gX®   c ¤  gJÃ n2Ã q
Uo"%l" f'.³ mX{",><[]-+."gXmZ{Zc s2 gJ} n2} q

Uo"%l"      // Get rid of all non-letter chars in U.
f'.³        // Take each set of three chars in U.
mX{      }  // Map each item X in this group to:
XmZ{     }  //  Map each letter Z in X to:
Zc s2 gJ    //   Take the char code of Z as a binary string, and take the first char.
            //   This maps each character to 1 if it's UC, or 0 if it's lc.
        n2  //  Interpret the result as a binary number.
",><[]-+."g //  Get the item at this index in this string.
q           // Concatenate the result and implicitly output.
share|improve this answer

Pyth, 40 bytes

jkm@"><[]-+.,"id2f!%lT3cm?rId0Z1f!rIT2z3

Try it here!

Could save 2 bytes if I can output the result as list of characters instead of a string.

Explanation

Filters out all non-letters, converts uppercase to 1 and lowercase to 0, splits into chunks of 3, interprets every chunk as binary number and uses this as index into a string which contains all BF commands.

jkm@"><[]-+.,"id2f!%lT3cm?rId0Z1f!rIT2z3  # z = input

                                f     z   # filter input with T
                                 !        # logical not
                                  rIT2    # T == swapcase(T), true if T is not a letter
                        m                 # map filter result with d
                         ?rId0            # if d == toLower(d)
                              Z1          # 0 for lowercase, 1 for uppercase
                       c               3  # Split into chunks of 3, last element is shorter if needed
                 f                        # filter with T
                  !                       # logical not
                   %lT3                   # len(t) mod 3 -> keep only elements of length 3
  m                                       # map with d
              id2                         # Convert from binary to decimal
   @"><[]-+.,"                      # Get the resulting BF command
jk                                        # Join to a string
share|improve this answer

JavaScript (ES6), 111 95 bytes

s=>s.match(/[A-Z]/gi).map(c=>+(c<'a')).join``.match(/.../g).map(g=>'><[]-+.,'['0b'+g|0]).join``

Simply removes non-letters, converts upper case letters into 1s and lower case into 0s, divides into groups of three, ignores a trailing group of 1 or 2, and decodes the groups.

Edit: Saved 16 bytes thanks to @dev-null, although the code no longer works when passed the empty string.

share|improve this answer
    
@dev-null Ugh, I had tried the match(/.../g).map().join approach but miscounted the number of bytes and though it didn't save me anything. Thanks for the tip on the first match though. – Neil Feb 28 at 21:18

Jolf, 31 34 bytes

Try it here! Replace with \x10 and with \x05. Because I implemented the chop function wrong, I gain 3 bytes. :(

►ΜZeZcAAρi♣Epu1pl033d."><[]-+.,"ΙH
        ρi♣E                        remove all space in input
       A    pu1                     replace all uppercase letters with 1
      A        pl0                  replace all lowercase letters with 0
    Zc            3                 chop into groups of three
  Ze               3                keep groups of length three
 Μ                  d               map
                              ΙH   parse element as binary
                     ."><[]-=.,"    and return a member of that
►                                  join by nothing
share|improve this answer

Python 3, 91 bytes

b=1
for c in input():
 b=-~c.isalpha()*b+c.isupper()
 if b>7:print(end="><[]-+.,"[b-8]);b=1

Hmm... looks a bit long, especially the second line. b=[b,2*b+(c<'a')][c.isalpha()] is slightly worse though.

share|improve this answer
1  
Using end like that is really smart. I've never seen that before. – Morgan Thrapp Feb 29 at 1:46

Hoon, 212 bytes

=+([v=turn c=curr q=cold k=tape] |=(t/k `k`(v (v `(list k)`(need ((unit (list k)) p:(rose (murn t (c rush alf)) (star (stun [3 3] ;~(pose (q '0' low) (q '1' hig))))))) (c scan bin)) (c snag (rip 3 '><[]-+.,')))))

Ungolfed:

|=  t/tape
^-  tape
%+  turn
  %+  turn  ^-  (list tape)
  %-  need  %-  (unit (list tape))
    =+  t=(murn t (curr rush alf))
    p:(rose t (star (stun [3 3] ;~(pose (cold '0' low) (cold '1' hig)))))
  (curr scan bin)
(curr snag (rip 3 '><[]-+.,'))
  1. use ++murn to get rid of all characters in the input that can't be parsed with "alf" (alphabet)
  2. parse the list with a combinator that outputs each 3 characters at a time to a list, replacing lowercase with '0' and uppercase with '1'
  3. Cast the result to (unit (list tape)) and forcibly unwrap it to get the furthest parsed result, to work with only multiple of threes without crashing
  4. Map over the list, parsing each group as if it were binary
  5. Use each number in the list as an index into the text '><[]-+.,', and cast the list back out to a tape.

Hoon doesn't have proper regular expressions, only a parser combinator library, so it's sadly pretty verbose. ++scan also crashes if the entire input stream isn't parsed, so I have to use ++rose, coerce it into a unit, and unwrap it for the "farthest parse" value. It also makes heavy use for currying and mapping over lists (++turn), so I alias the function names to one letter variables.

Hoon is the programming language for Urbit, a clean slate reimplementation project. It's purely functional, statically typed, vaguely lisp-like, and compiles to Nock. Nock is a combinator based VM that runs on top of a binary tree bignum memory model.

When you boot Urbit you are dropped into :dojo, the shell and Hoon repl. To run the snippet simply type:

%.  "PROgRam reVERsES giVeN iNPut sEqUENcE"

and then paste the standalone function on the next line.

share|improve this answer
    
Welcome to PPCG! You answer is fairly well explained, but could you link in an interpreter or a place to try it online? – VTCAKAVSMoACE Feb 29 at 0:07
    
I added a link to Urbit's github page, since building it is pretty much the only way. Is that sufficient? – RenderSettings Feb 29 at 0:18
    
Absolutely. :D Leaving instructions on how to use this in a full program as well would be wonderful. – VTCAKAVSMoACE Feb 29 at 0:25

Jelly, 27 bytes

=Œs¬Tịµ=Œu;0s3ṖḄ€ị“<[]-+.,>

Try it online! Note that backslashes need escaping in the input string for the second last test case.

Implicit input: string s (list of characters)

=Œs             Compare with swapcase
¬               Not - this gives 1 for letters, 0 otherwise
Tị              Take characters at truthy indices
µ               Start a new monadic chain

Input: string s' (list of letters)

=Œu             Compare with uppercase
;0              Append 0
s3              Split into chunks of length 3
Ṗ               Pop last chunk
Ḅ€              Apply convert-from-binary to each chunk
ị“<[]-+.,>      For each number, 1-based index cyclically into the string "<[]-+.,>"
share|improve this answer

Matlab, 98 bytes

function t(s);s=s(isletter(s));s=s(1:end-mod(end,3));r='><[]-+.,';r([4 2 1]*reshape(s<92,3,[])+1)
  1. Clean
  2. Trim
  3. reshape into a 3xn Matrix m with UC = 1, lc =0
  4. (4 2 1)*m+1 results in an index list
  5. Index to the right chars
share|improve this answer

Perl, 76 73 72 + 1 = 73 bytes

$a.=y+A-Z++dfor/[A-Z]/gi;print substr"><[]-+.,",oct"0b$_",1for$a=~/.../g

Requires the -n flag:

$ perl -n oOo.pl <<< 'PROgRamr{}\eVERsESgiVeNiNPutsEqUENcE'
,[>,]<[.<]+

Using the trick with base-2 conversion.

How it works:

                          # '-n' auto read first line into `$_`
            for/[A-Z]/gi; # Iterate over all letters a-z
$a.=y/A-Z//d              # Count number of uppercase letters (1 or 0)

                                  for$a=~/.../g # Split $b into hunks of 3 characters. And
                                                # remove any potential trailing characters.
      substr"><[]-+.,",oct"0b$_",1              # `oct("0b$binary")` will convert binary
                                                # to decimal.
print
share|improve this answer

Julia, 107 bytes

s->"><[]-+.,"[map(j->parse(Int,j,2)+1,[map(i->i<'_'?'1':'0',m)for m=matchall(r"\w{3}",filter(isalpha,s))])]

This is an anonymous function that accepts a string and returns a string. To call it, assign it to a variable.

Ungolfed:

function f(s)
    # Brainfuck commands
    bf = "><[]-+.,"

    # Filter out non-alphabetic characters from the input
    chars = filter(isalpha, s)

    # Get all non-overlapping groups of three characters
    groups = matchall(r"\w{3}", chars)

    # Construct binary strings by comparing to _
    binary = [map(i -> i < '_' ? '1' : '0', m) for m = groups]

    # Parse each binary string as an integer and add 1
    indices = map(j -> parse(Int, j, 2) + 1, binary)

    # Return the Brainfuck commands at the indices
    return bf[indices]
end
share|improve this answer

Lua, 120 Bytes

Big use of string.gsub() here, one more time could have allowed me to create a one character pointer on this function to gain some bytes. Also, it is my first lua program without any spaces! :D

This program takes its input via command-line argument and output a BrainFuck program, one command per line.

Edit: Saved 1 Byte thanks to @Oleg V. Volkov

arg[1]:gsub("[%A]",""):gsub("%l",0):gsub("%u",1):gsub("...",function(c)x=1+tonumber(c,2)print(("><[]-+.,"):sub(x,x))end)

Ungolf and explanations

arg[1]:gsub("[%A]","")    -- replace the non-letter character by an empty string
                          -- %A matches all the character not in %a (letters)
:gsub("%l",0)             -- replace lower case letters by 0s
:gsub("%u",1)             -- replace upper case letters by 1s
:gsub("...",function(c)   -- iterate over all groupe of 3 characters
  x=tonumber(c,2)+1       -- convert the 3-letter group from binary to decimal
  print(("><[]-+.,")      -- output the corresponding brainfuck command
             :sub(x,x))   
end)
share|improve this answer
    
You can save one byte on inlining b and one more on saving string.gsub to shorter var and manually folding first arguments to it: g=("").gsub g(g(g(g(arg[1],"[%A]",""),"%l",0),"%u",1),"...",function(c)x=1+tonumber(c,2)prin‌​t(("><[]-+.,"):sub(x,x))end) – Oleg V. Volkov Feb 29 at 19:15
    
...or maybe I misread byte count on folding. Inlining still works. – Oleg V. Volkov Feb 29 at 19:31
    
@OlegV.Volkov Saving to a shorter var costs, sadly, more, I tried the same thing ^^. And thanks for the inlining of b... I don't know why I saved it in a var... – Katenkyo Mar 1 at 7:36

Python 2, 112 bytes

''.join('><[]-+.,'[int('%d'*3%tuple(map(str.isupper,y)),2)]for y in zip(*[iter(filter(str.isalpha,input()))]*3))

Will try to golf it more.

share|improve this answer

Mathematica, 192 bytes

StringJoin[FromDigits[#,2]&/@Partition[ToCharacterCode@#-48,3]&[StringDelete[#,a_/;!LetterQ[a]]~StringReplace~{_?UpperCaseQ->"1",_?LowerCaseQ->"0"}]/.Thread[0~Range~7->Characters@"><[]-+.,"]]&

Anonymous function that takes the desired string as an argument. Steps in the (pretty straightforward) algorithm:

  1. Clean the string
  2. Replace UC->"1", lc->"0"
  3. Turn the string into a binary list
  4. Partition the list into threes and interpret each chunk as a base-2 number
  5. Replace the numbers with their appropriate symbols and join back into a string.
share|improve this answer

Ruby 117 114 113 111 86 79 Bytes

gets.tr(?^+m='a-zA-Z','').tr(m,?0*26+?1).scan(/.../){$><<"><[]-+.,"[$&.to_i 2]}
  • tr(?^+m='a-zA-Z','') sets m to 'a-zA-Z' and removes non-letters
  • .tr(m,?0*26+?1) converts lowercase to 0, uppercase to 1
  • .scan(/.../) chunk string into groups of 3 and discard last group if it has less than 3
  • {$><<"><[]-+.,"[$&.t‌​o_i 2]} convert each binary number to a character
share|improve this answer
    
Can't you use tr("a-zA-Z","01")? or even tr("A-Za-z",10) – andlrc Feb 29 at 0:12
    
@dev-null "AAz".tr("a-zA-Z","01") gives 111 – FuzzyTree Feb 29 at 0:19
1  
So much that can be done here. This is a start: gets.delete('^a-zA-Z').tr("a-z",?0).tr("^0",?1).scan(/.../){$><<"><[]-+.,"[$&.t‌​o_i 2]} (86 bytes). Changed the input from command line option to stdin; fixed the surrounding quotes in the output (but now it has no trailing newline) – daniero Feb 29 at 6:44
    
@daniero thanks! made this a community answer. feel free to make changes – FuzzyTree Mar 1 at 0:49
1  
tr(^a-zA-Z','').tr('a-zA-Z',?0*26+?1) is shorter – Not that Charles Mar 1 at 23:08

Perl 6, 81 bytes

This can probably be done better, but this is my go at it

{m:g/:i<[a..z]>/;[~] ("><[]-+.,".comb[:2[$_]]for (+(91>$_.ord)for |$/).rotor(3))}

Usage

> my &f = {m:g/:i<[a..z]>/;[~] ("><[]-+.,".comb[:2[$_]]for (+(91>$_.ord)for |$/).rotor(3))}
-> ;; $_? is raw { #`(Block|149805328) ... }
> f("PROgRamreVERsESgiVeNiNPutsEqUENcE")
,[>,]<[.<]+

Ungolfed

sub oOo ($_) {
    m:g/:i<[a..z]>/;  # Match all letters and put them in $/

    my @digits = (                
        for |$/ -> $c {           # For all $c in $/
            +(91>$c.ord)          # 1 if $c.ord < 91 else 0
        }
    );
    @digits.=rotor(3);            # Split the digits into chunks of 3

    my @chars = (
        for @digits -> @l {
            "><[]-+.,".comb[:2[@l]] # Take the character from "><[]-+.,"
                                    # at an index given by converting 
                                    # @l (a list of 3 binary digits)
                                    # from base 2 to base 10
        }
    );
    @chars.join # Join the list of chars into a string and return
}
share|improve this answer

C++, 173 167 bytes

Full program, golfed (reads from standard input):

#include <cstdio>
main(){for(char*a="@[`{>-[.<+],",c,o=0,t=1;(c=getchar())>0;)if(c=c>*a&&c<a[1]?2:c>a[2]&&c<a[3]?1:0){o|=c>1?t:0;t*=2;if(t>4)putchar(a[o+4]),o=0,t=1;}}

Somewhat ungolfed:

#include <cstdio>
main(){
    for(char*a="@[`{>-[.<+],",c,o=0,t=1;(c=getchar())>0;)
        if(c=c>*a&&c<a[1]?2:c>a[2]&&c<a[3]?1:0){
            o|=c>1?t:0;
            t*=2;
            if(t>4)putchar(a[o+4]),o=0,t=1;            
        }
}

Note that @A ... Z[ in ASCII, and likewise for `a ... z}.

share|improve this answer

Pyke, 31 bytes, noncompetitive

Pyke is older than the challenge and I added some features to make it more competitive - chunk function. I used the same trick as @Martin Büttner used.

#~l{)\`Lm<0+3cFb2"><[]-+.,"@)st

Try it here!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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