56
\$\begingroup\$

Challenge

The goal is to output Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo.

Context. (Maybe another interesting challenge could be printing all of the other examples? This would probably use similar logic but involve either a function or just a for loop.)

Rule(s)

  1. You cannot output anything other than the string with correct casing and spacing. Trailing new lines are allowed, trailing spaces are not.

This is , so fewest bytes win!

\$\endgroup\$
1
  • 3
    \$\begingroup\$ By the way, there is also an anarchy golf version of this question. \$\endgroup\$ Commented Jan 31, 2021 at 1:26

93 Answers 93

3
\$\begingroup\$

Ohm v2, 20 bytes

‥bB.¢`b}®:_”cåχíð”↔ù

Try it online!

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

brainfuck, 370 bytes

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

Try it online!

Not exactly the most optimized answer and could probably be golfed much further. Makes lots of use of copying cells, as well as repeadedly performing the same print function near the end.

Original un-minified version (sadly uncommented) can be found here.

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

T-SQL, 45 51 47 bytes

PRINT REPLACE('B0 B0 b0 B0',0,'uffalo buffalo')

PRINT is shorter than SELECT. Using a numeral in the REPLACE eliminates a set of quotes and saves 2 bytes.

EDIT: Fixed trailing space, at the cost of 6 bytes. Saved 4 by replacing a longer phrase, thanks @Giuseppe

\$\endgroup\$
4
  • \$\begingroup\$ This has a trailing space, which isn't allowed in the rules \$\endgroup\$ Commented Feb 1, 2021 at 20:46
  • \$\begingroup\$ @ijustlovemath Fixed \$\endgroup\$
    – BradC
    Commented Feb 1, 2021 at 20:50
  • \$\begingroup\$ You should be able to do something like this \$\endgroup\$
    – Giuseppe
    Commented Feb 1, 2021 at 20:56
  • \$\begingroup\$ Thanks, @Giuseppe, that save a few bytes. I don't believe the period at the end is required, though. \$\endgroup\$
    – BradC
    Commented Feb 1, 2021 at 21:08
3
\$\begingroup\$

PHP, 47 45 bytes

while($x<8)echo~_[!$x],BbBbbbBb[$x++],uffalo;

Try it online!

-2 bytes thx to @manatwork!

\$\endgroup\$
2
  • \$\begingroup\$ Impressing one! Including bending a bit the “correct casing and spacing” rule by outputting no-break space instead of regular space. BTW, no need for the braces. \$\endgroup\$
    – manatwork
    Commented Feb 2, 2021 at 22:10
  • \$\begingroup\$ @manatwork thanks! Of course I don't need the braces! Silly me!! \$\endgroup\$
    – 640KB
    Commented Feb 2, 2021 at 22:13
3
\$\begingroup\$

K (ngn/k), 27 25 bytes

-2 bytes thanks to ngn!

" "/"BbBbbbBb",\:"uffalo"

Try it online!

J, 30 bytes

echo}:,/'BbBbbbBb',"{'uffalo '

Try it online!

\$\endgroup\$
3
  • 1
    \$\begingroup\$ k: slightly shorter if you use join (" "/) \$\endgroup\$
    – ngn
    Commented Feb 2, 2021 at 12:50
  • \$\begingroup\$ @ngn I totally forgot join - thank you! I'll update the solution when TIO allows me (can't open it right now) \$\endgroup\$ Commented Feb 2, 2021 at 12:56
  • \$\begingroup\$ @Dingus Thank you! Apparently I haven't copied the text :) \$\endgroup\$ Commented Feb 3, 2021 at 11:09
3
\$\begingroup\$

Java (JDK), 49 bytes

v->"B b B b b b B b".replaceAll("b|B","$0uffalo")

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to Code Golf, nice first answer! \$\endgroup\$
    – rydwolf
    Commented Feb 3, 2021 at 15:48
3
\$\begingroup\$

PowerShell, 41 38 bytes

-3 bytes thanks to @mazzy

'BbBbbbBb'-replace'.',' $0uffalo'|% *m

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ you can use method trim instead substring :) \$\endgroup\$
    – mazzy
    Commented Feb 3, 2021 at 20:13
3
\$\begingroup\$

QBasic, 43 bytes

u$="uffalo buffalo
?"B"u$" B"u$" b"u$" B"u$

Abuses a couple tricks with the autoformatter (besides the standard ? for PRINT shortcut): the missing double quote is added at the end of line 1, and semicolons are inferred in the print statement whenever a literal string is next to a variable. After expansion, the code becomes

b$ = "uffalo buffalo"
PRINT "B"; b$; " B"; b$; " b"; b$; " B"; b$

The semicolon trick, plus the fact that string variables need the $ sigil, meant that approaches using more variables to build the string ended up longer.

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

Java (JDK), 49 bytes

v->"B b B b b b B b".replaceAll("\\w","$0uffalo")

Try it online!

Credits

\$\endgroup\$
7
  • 1
    \$\begingroup\$ 50 bytes \$\endgroup\$ Commented Feb 1, 2021 at 10:31
  • \$\begingroup\$ Nice find, @KevinCruijssen I was golfing byte by byte and you with a totally different approach, thanks :) \$\endgroup\$ Commented Feb 1, 2021 at 10:41
  • \$\begingroup\$ You can save another byte by moving the spaces to the string. Try it online! \$\endgroup\$
    – Jo King
    Commented Feb 4, 2021 at 5:36
  • \$\begingroup\$ 41 bytes \$\endgroup\$
    – branboyer
    Commented Mar 7, 2021 at 5:25
  • \$\begingroup\$ @branboyer actually, trailing spaces are explicitly disallowed, but thanks! \$\endgroup\$ Commented Mar 7, 2021 at 9:16
3
\$\begingroup\$

x86-16 machine code, IBM PC DOS, 35 33 32 bytes

00000000: b820 09b1 e7ba 1801 cd21 d0e9 7409 7303  . .......!..t.s.
00000010: 3044 19cd 29eb f1c3 4275 6666 616c 6f24  0D..)...Buffalo$

Listing:

B8 0920     MOV  AX, 0920H          ; AH = 9 DOS string function, AL = ' ' 
B1 E7       MOV  CL, 11100111b      ; magic buffalo number 11100111 
BA 0118     MOV  DX, OFFSET BUF     ; 'Buffalo' pointer for display 
        STAMPEDE:
CD 21       INT  21H                ; write our *uffalo to screen 
D0 E9       SHR  CL, 1              ; LSB of magic buffalo number into CF 
74 09       JZ   BYE_BUFFALO        ; loop until CL is 0 
73 03       JNC  HI_BUFFALO         ; if LSB bit is a 0, don't change case 
30 44 19    XOR  [SI+BUF-100H], AL  ; swap case on first letter 
        HI_BUFFALO:  
CD 29       INT  29H                ; if not last of the buffalo, display a space 
EB F1       JMP  STAMPEDE           ; keep 'em coming 
        BYE_BUFFALO: 
C3          RET                     ; return to DOS 
        BUF:
            DB   'Buffalo$'         ; the real Buffalo

Try it online!

Explanation:

Uses the byte 0xe7 (1110 0111 binary) to determine if the case should be swapped. Each [Bb]uffalo corresponds to the next least significant bit of the byte where a 1 means to change the case and a 0 means don't change.

The case of the first character can be alternated by doing an xor 0x20 on the ASCII value. Now 0x20 just happens to be the ASCII value for a space character, so we can put that in al and use for both the xor and to write the space character.

enter image description here

Props:

  • -1 byte thx to @peter ferrie!
\$\endgroup\$
3
  • \$\begingroup\$ XOR [SI+BUF-100h] allows dropping the MOV BX,DX, if SI=100h on entry like it is in MS-DOS. \$\endgroup\$ Commented Feb 4, 2021 at 23:02
  • \$\begingroup\$ XOR [SI+19],AL is 3 bytes. \$\endgroup\$ Commented Feb 5, 2021 at 19:24
  • \$\begingroup\$ Oh, I see - it looks like my assembler was using the 4 byte opcode (80 84 1A 00 / XOR [SI+001A], AL when doing the pre-processor math. In that case, it's a 1 byte win! Thanks! \$\endgroup\$
    – 640KB
    Commented Feb 5, 2021 at 19:46
3
\$\begingroup\$

Scratch, 8 blocks

hi if you’re reading this

Try it on scratch!

I tried to refrain from doing anything too illegal like setting the costume as Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo or setting a variable as that.

Here is the scratchblocks code (102 bytes):

when gf clicked
for each[i v]in(8){set[B v]to(join(B)(join(letter(i)of[BbBbbbBb])[uffalo ])
}::control

Usually when people submit scratch, they submit Tosh (https://tosh.blob.codes/), which is Scratch but text-based or an image of the blocks compiled on scratchblocks (https://scratchblocks.github.io). I would’ve done both, but the for each [i v] in (8) block is old and removed and I can’t figure out how to do it on Tosh.

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

brainfuck, 190 179 bytes

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

Try it online!

The ASCII codes are initialised using a similar method to my Buffalo answer, though here both b and the second f get their own cells. Printing the output requires fewer instructions in brainfuck compared with Buffalo because of a key difference in the way that loops are handled: brainfuck uses the currently active cell to decide whether a loop ends, whereas Buffalo refers back to the cell that was originally active when the loop was entered. Consequently, we can print runs of letters in successive cells with a simple [.>] loop in brainfuck, a construction that isn't possible in Buffalo.

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

Jelly, 15 13 bytes

“ƤhƤDȷ»Ḳ162ṃK

Try it online!

        162ṃ     Convert 162 to binary, and 1-index each digit into
“ƤhƤDȷ»          "Buffalo buffalo"
       Ḳ         split on spaces.
            K    Join on spaces.

I was in fact doing something terribly wrong 3 (almost 4) years ago, but this still comes out two bytes shorter than title-casing dynamically:

Jelly, 17 15 bytes

162B“¦ȯø»Œtṛ¡ⱮK

Try it online!

162B               Convert 162 to binary,
             Ɱ     and for every digit
         Œt        title-case
    “¦ȯø»          "buffalo"
           ṛ¡      that many times.
              K    Join on spaces.
\$\endgroup\$
2
\$\begingroup\$

Red, 57 bytes

prin collect[foreach b"BbBbbbBb"[keep rejoin[b"uffalo"]]]

Try it online!

Alternative:

Red, 60 bytes

parse s:"B b B b b b B b"[any["b"insert"uffallo"|" "]]prin s

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Stax, 16 bytes

Æ▼.#t!♦ΩÿN+╪\7êI

Run and debug it

Uses mixed base conversion and some zipping.

Made with a lot of @recursive's help.

\$\endgroup\$
2
\$\begingroup\$

C++11, 126 bytes

#include<random>
#include<cstdio>
int main(){std::knuth_b g(7);for(char i{},s[]=" buffalo";i-8;++i)s[1]^=*s&g(),printf(s+!i);}

Try it online!

Not a serious contender for shortest program — but I was inspired by the (original, now-deleted) requirement not to use a random number generator. ;)

\$\endgroup\$
2
\$\begingroup\$

Python 3, 117 bytes

o=['buffalo']
for x in ['B' if int(i) else 'b' for i in bin(69)[:1:-1]]:
  o.insert(0,x+o[-1][1:])
print(' '.join(o))

Try it online!

69 is the reverse of the binary representation of the capitalization pattern.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ Welcome to Code Golf, nice first answer! I don't know much Python but you may want to check out Tips for golfing in Python. \$\endgroup\$
    – rydwolf
    Commented Feb 1, 2021 at 22:51
  • 1
    \$\begingroup\$ 'B' if int(i) else 'b' -> 'bB'[int(i)], and you can remove a space before for. Also, you could .append instead of .insert and use o[::-1] later, and you can then write o+=[item] in place of o.append(item). \$\endgroup\$
    – Bubbler
    Commented Feb 2, 2021 at 9:48
2
\$\begingroup\$

Perl 5, 37 bytes

say"@{[map{(21%$_?b:B).uffalo}1..8]}"

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Bubblegum, 17

Obligatory bubblegum answer generated with zopfli --deflate --i1000 -c buffalo.txt | xxd

00000000: 732a 4d4b 4bcc c957 4882 d2e8 fc24 fcf2  s*MKK..WH....$..
00000010: 00                                       .

Try it online!

\$\endgroup\$
2
\$\begingroup\$

Raku, 33 30 bytes

put "BbBbbbBb".comb X~"uffalo"

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ >>~>> can just be X~ \$\endgroup\$
    – Jo King
    Commented Feb 5, 2021 at 3:23
2
\$\begingroup\$

Rattle, 51 46 42 bytes

Rattle just hit release today - this is my first golf with the released version! If you're interested in learning a fun and easy new language, I would highly recommend checking it out!

B&b&uffalo& |I=[b0[2b^b1]b2b3b1b2[3q]b3+]4

Try it online!

Try to out-golf me! You'll probably want to consult the documentation

Explanation

B&b&uffalo&      creates an array of hard-coded strings: ["B","b","uffalo"," "]
    |            syntax for taking input
     I           stores this data in first memory slots
      =          sets top of stack to 0
       [ ... ]4  loops 4 times
    b0           adds item in slot 0 to buffer
      [2 ... ]   executes statements inside if top of stack is equal to 2
        b^       deletes last item from buffer
          b1     adds item in slot 1 to buffer
    b2b3b1b2     adds item in slot 2, 3, 1, 2 to buffer
    [3 ... ]     executes statement inside if top of stack is equal to 3
      q          ends program - buffer is implicitly printed
    b3           adds item in slot 3 to buffer
      +          adds 1 to top of stack
\$\endgroup\$
2
\$\begingroup\$

Regenerate, 27 bytes

B((uffalo) b$2 B$2 b$2) b$1

Attempt This Online!

Pretty simple: golf repeated substrings using capture groups.

\$\endgroup\$
2
\$\begingroup\$

MathGolf, 18 bytes

9G*âx{ûbB§╕«Γ╢ô };

Try it online.

âx{ûbB§╕«Γ╢ô could alternatively be à{ENR**╦\i╛δ for the same byte-count: try it online.

Explanation:

9G*               # Push 9*18=162
   â              # Convert it to a binary list
                  # (which is unfortunately in reversed order due to a bug)
    x             # Reverse it to the correct order
     {            # Loop over each of these bits as integers:
      ûbB         #  Push string "bB"
         §        #  (0-based) index the current bit into it
          ╕«Γ     #  Push compressed string "uffa"
             ╢ô   #  Push compressed string "lo"
                  #  Push a space character " "
     };           # After the loop: discard the final space
                  # (after which the entire stack is joined and output implicitly)

   à              # Convert it to a binary string (in correct order..)
    {             # Loop over each of these bits as characters:
     ENR**        #  Push 15*25*29=10875
          ╦       #  Get the dictionary word at this index: "buffalo"
           \      #  Swap so the current bit is at the top of the stack
            i     #  Convert it from a character to an integer
             ╛    #  If it's truthy:
              δ   #   Titlecase the string
\$\endgroup\$
2
\$\begingroup\$

sed, 35 33 bytes

-2 bytes thanks to user41805

s/^/BbBbbbBb/
s/./ &uffalo/g
s///

Attempt This Online!

34B solution:

-1 byte thanks to user41805

s/^/B b B b b b B b/
s/\>/uffalo/g

Attempt This Online!

35B solution: (The regex matches empty string at first and then is reused for the second s command)

s/b*/B b B b b b B b/i
s//&uffalo/g

Attempt This Online!

\$\endgroup\$
7
  • \$\begingroup\$ Hint: you can get 34b with both solutions. \$\endgroup\$
    – user41805
    Commented Jan 5, 2023 at 16:02
  • \$\begingroup\$ @user41805 Hmm, I am unable to figure it out, what is the solution? \$\endgroup\$
    – Jiří
    Commented Jan 7, 2023 at 22:21
  • 1
    \$\begingroup\$ For the above approach, it seems the $ in s/.$// is annoying, something you can do to remove its need? For the second approach, try finding an alternative to \w so you can rid the & in the substitution \$\endgroup\$
    – user41805
    Commented Jan 12, 2023 at 15:08
  • \$\begingroup\$ @user41805 Thank you! Both solutions are smart and something I couldn't think of without your help. And it even got to 33B. \$\endgroup\$
    – Jiří
    Commented Jan 13, 2023 at 8:33
  • \$\begingroup\$ Nice find! Btw if you're interested, I have an infinite bounty for a sed submission to a specific challenge codegolf.meta.stackexchange.com/a/23852 \$\endgroup\$
    – user41805
    Commented Jan 14, 2023 at 14:30
2
\$\begingroup\$

Joeasus, 29 27 23 bytes

pp![BufflotongueTwister

Run Peq Online

-2 thanks to emanresu A

-4 thanks to lyxal

Joeasus is a joke programming language "interpreted" by the Llama 3 LLM, prompted with a minimal description of itself under the name "Peq". It's often very bad at this, forgetting that it's supposed to be a programming language at all or refusing to bullshit functionality for various operators, not to mention it's virtually unusable outside Kolmogorov complexity challenges, but the bright side is that it can also hallucinate its way out of typos.

A previous solution I nearly posted was C.BufflobTongueTwisterNoPeriod for 30 bytes. Getting it to "programmatically" strip the trailing period is much harder than making it imagine the constant hardcoded that way, or at least without also surrounding the output with extraneous quotes, and one of the few "ground truths" about the language is the presence of a "library of helpful constants" named CT--which in this case I can apparently just abbreviate to C.

\$\endgroup\$
2
  • 1
    \$\begingroup\$ this seems to work for 27 \$\endgroup\$
    – emanresu A
    Commented Nov 21 at 23:08
  • 1
    \$\begingroup\$ 23 bytes \$\endgroup\$
    – lyxal
    Commented Nov 22 at 4:56
1
\$\begingroup\$

Wolfram Language (Mathematica), 48 bytes

##<>#&//"B"~Print~#["uffalo"~#~b~#~" B",b=" b"]&

Try it online!

Port of TiKevin83's TI-BASIC solution.

\$\endgroup\$
1
\$\begingroup\$

Clojure, 60 bytes

(clojure.string/join " " (map #(str % "uffalo") "BbBbbbBb"))
\$\endgroup\$
1
\$\begingroup\$

C#, 131 bytes

using System.Linq;using System;class A{static void Main(){Console.Write($"{String.Join("uffalo ", "BbBbbbBb".ToArray())}uffalo");}}

Try it online!

\$\endgroup\$
1
\$\begingroup\$

Pyth, 22 bytes

jdm+d"uffalo""BbBbbbBb

Try it online!

\$\endgroup\$
1
\$\begingroup\$

jq, 35 characters

"BbBbbbBb "/""|join("uffalo ")[:-2]

Sample run:

bash-5.0$ jq -nr '"BbBbbbBb "/""|join("uffalo ")[:-2]'
Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo

Try it online!

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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