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

1
\$\begingroup\$

Pyth, 23 22 bytes

Save a byte thanks to @Scott!

V"BbBbbbBb"p+N"uffalo 

Try it online!


I wanted to be smart and encode the state of the upper- and lowercase letters as bits, but that ended up taking a byte more. Here's the code and explanation anyway!

24 bytes

FNj162 2p+?N\B\b"uffalo 
FN                         # loop with N
  j162 2                   # convert 162 into binary as list of bits
        p                  # print without newlines
         +                 # concatinate strings
          ?N\B\b           # ternary operator, checks if the bit is falsey (0)
                "ufallo    # note the trailing space
\$\endgroup\$
2
  • 1
    \$\begingroup\$ The 'V' function is equivalent to FN, so you can save a byte with V"BbBbbbBb"p+N"uffalo \$\endgroup\$
    – Scott
    Commented Feb 3, 2021 at 21:18
  • \$\begingroup\$ Also 22 bytes using map: jdm+d"uffalo""BbBbbbBb \$\endgroup\$
    – Scott
    Commented Feb 3, 2021 at 21:27
1
\$\begingroup\$

Ruby, 49 39 bytes

-10 bytes thanks to Dingus

$><<('BbBbbbBb '.chars*'uffalo ').strip

Try it online!

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

Julia REPL, 33 bytes

join("BbBbbbBb ","uffalo ")[1:63]

Julia, 40 bytes

print(join("BbBbbbBb ","uffalo ")[1:63])

\$\endgroup\$
1
  • \$\begingroup\$ @Dingus Thanks for informing me of that. I editted the answer. \$\endgroup\$
    – spacetyper
    Commented Feb 5, 2021 at 2:46
1
\$\begingroup\$

brainfuck, 226 bytes

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

Try it online!

The cells are set to <space>Bbuffalo

<[<]> Goto the space cell
.  (dot = print a space)
>. (dot = print B)
>. (dot = print b)
>[.>] print uffalo

Buffalo is printed using <[<]>.>.> >[.>] but is this if it is the first time, we use <[<]> >.> >[.>]

buffalo is printed using <[<]>.> >.>[.>] but we can golf this to <[<]>.> > [.>]

The only thing that I can think of that could probably be better golfed is the preparation part.

If you put the B before the space you might be able to save some bytes.

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

ThumbGolf, 31 bytes

Machine code (little endian pairs):

a005 22ba 0852 bf2c 2162 2142 de11 de00
d001 de3b d1f6 4770 6675 6166 6f6c 00

Commented assembly:

        // Include ThumbGolf wrapper macros
        .include "thumbgolf.inc"
        .globl main
        .thumb_func
main:
        // r0 = "uffalo"
        adr     r0, .Luffalo
        // Bitmask representing the case of the B.
        // 0 = B, 1 = b, little endian bit order.
        // Also allows us to determine the length.
        // This fits perfectly into a narrow movs.
        //             bBbbbBbB
        movs    r2, #0b10111010
.Lloop:
        // Read a bit from the bitmask into the carry flag by shifting right.
        // Also detects when we have read all of the bits: lsrs will set the
        // zero flag.
        lsrs    r2, r2, #1
        // r1 = (r2 & 1) ? 'b' : 'B'
        ite     cs
        movcs   r1, #'b'
        movcc   r1, #'B'
        // print either 'b' or 'B'
        putc    r1 // udf #0021
        // print "uffalo" (w/o newline)
        puts    r0 // udf #0000
        // Yes, none of the output instructions affect the flags despite using
        // stdio AND executing the stdio call on the main thread (since stdio in
        // signal handlers is unsafe), and this is proof.
        //
        // If the bitmask is zero, exit.
        it      eq
        bxeq    lr
        // Use the "put special" instruction to print a space.
        putspc  ' ' // udf #0073
        // More flexing that the flags are preserved, it is just as good to do
        // `b .Lloop`.
        // The proof is that this won't crash, since the ASCII as code will store
        // random garbage to uninitialized registers.
        bne     .Lloop
        // string literal
.Luffalo:
        .asciz "uffalo"

Mostly a demo to show how ThumbGolf preserves the condition flags on output instructions.

I could do the same thing with cbz and an unconditional b, but this is a nice party trick.

As I explained in the code, I use a bitmask to control whether Buffalo or buffalo is printed. It just happens to be a perfect 8-bit constant for movs.

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

Javascript, 57 bytes

console.log('BbBbbbBb'.replace(/./g, '$&uffalo ').trim())

Try it online!

If a trailing space is allowed, it can be 50 bytes:

console.log('BbBbbbBb'.replace(/./g, '$&uffalo '))

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ What language is this? \$\endgroup\$
    – Wheat Wizard
    Commented Feb 5, 2021 at 12:20
  • 1
    \$\begingroup\$ Seems like JavaScript to me. Works perfectly in JS. \$\endgroup\$
    – Makonede
    Commented Feb 8, 2021 at 2:20
1
\$\begingroup\$

Kotlin, 63 bytes

fun main(){"BbBbbbB".map{print(it+"uffalo ")};print("buffalo")}

Kotlin Playground

I used the fairly common strategy of concatenating the first letter to "uffalo", but I had to print the last one to avoid trailing white space, I'm yet to find a better solution.

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

AWK, 52 bytes

BEGIN{B="Buffalo";b="buffalo";print B,b,B,b,b,b,B,b}

Try it online!

I could not come up with a shorter example.

\$\endgroup\$
18
  • \$\begingroup\$ I managed to get it to 49... with this BEGIN{for(u="uffalo ";++a<5;)b=b"B"u"b"u;print b} \$\endgroup\$
    – cnamejj
    Commented Nov 3, 2022 at 9:13
  • \$\begingroup\$ @cnamejj - unfortunately the seqeunce of B/b is not alternating, whereas your output is: check the 5th buffalo (not Buffalo)... \$\endgroup\$ Commented Nov 3, 2022 at 14:01
  • \$\begingroup\$ (I got 49 a different way: try it)... \$\endgroup\$ Commented Nov 3, 2022 at 14:42
  • \$\begingroup\$ @DominicvanEssen : got it to 48 : BEGIN{print (C="B"(_="uffalo ")"b"_)C"b"_"b"_ C} \$\endgroup\$ Commented Nov 3, 2022 at 22:01
  • \$\begingroup\$ @RAREKpopManifesto - When I run it here the output for the 5th buffalo doesn't seem right... \$\endgroup\$ Commented Nov 3, 2022 at 22:04
1
\$\begingroup\$

Whispers v2, 69 bytes

> "BbBbbbBb"
> "uffalo "
> -1
>> L+2
>> Each 4 1
>> 5ᶠ3
>> Output 6

Try it online!

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

Deadfish~, 463 bytes

{{i}dddd}iiiiiic{{i}ddddd}ic{d}dddddccdddddc{i}iciiic{{d}ii}ic{{i}dddd}iiiiiic{i}{i}dc{d}dddddccdddddc{i}iciiic{{d}ii}ic{i}{i}{i}iiiic{{i}ddddd}ic{d}dddddccdddddc{i}iciiic{{d}ii}ic{{i}dddd}iiiiiic{i}{i}dc{d}dddddccdddddc{i}iciiic{{d}ii}ic{{i}dddd}iiiiiic{i}{i}dc{d}dddddccdddddc{i}iciiic{{d}ii}ic{{i}dddd}iiiiiic{i}{i}dc{d}dddddccdddddc{i}iciiic{{d}ii}ic{i}{i}{i}iiiic{{i}ddddd}ic{d}dddddccdddddc{i}iciiic{{d}ii}ic{{i}dddd}iiiiiic{i}{i}dc{d}dddddccdddddc{i}iciiic

Try it online!

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

BBC BASIC, 55 bytes

F.I%=1TO8:P.CHR$(98+32*((I%AND(I%+1))=0));"uffalo ";:N.

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ Welcome to the site, and nice first answer! \$\endgroup\$ Commented Feb 24, 2021 at 14:16
1
\$\begingroup\$

JavaScript (V8), 57 50 bytes

a='uffalo';b='B'+a+' b'+a;c='b'+a;print(b,b,c,c,b)

Try it online!

You have to run these at Try it online! because running it in a browser console will try to print this webpage

57 bytes:

a='uffalo ';b='B'+a+'b'+a;c='b'+a;print(b+b+c+c+b.trim())

47 bytes but Try it online! doesn't understand String.replaceAll and it outputs a trailing space:

print('B'+('bBbbbBb'.replaceAll('','uffalo ')))

46 bytes but it outputs a trailing space (thanks to @lm42):

print('B'+('bBbbbBb'.replace(/|/g,'uffalo ')))

This is my first golf.

\$\endgroup\$
8
  • \$\begingroup\$ Welcome to Code Golf, nice first answer! \$\endgroup\$
    – rydwolf
    Commented Feb 2, 2021 at 6:12
  • \$\begingroup\$ Surely that last approach includes an unwanted trailing space? \$\endgroup\$
    – Neil
    Commented Feb 4, 2021 at 22:40
  • \$\begingroup\$ yes, I did not see that \$\endgroup\$ Commented Feb 4, 2021 at 22:45
  • 1
    \$\begingroup\$ print('B'+('bBbbbBb'.replace(/|/g,'uffalo '))) for last of your \$\endgroup\$
    – l4m2
    Commented Apr 9, 2021 at 13:12
  • \$\begingroup\$ @l4m2 this has a trailing space \$\endgroup\$ Commented Apr 9, 2021 at 23:25
1
\$\begingroup\$

R, 48 bytes

Similar to Dominic van Essen's recycling solution, but with paste0.

cat(paste0(scan(,''),'uffalo'))
B
b
B
b
b
b
B
b

Try it online!

Same idea, also 48 bytes

cat(paste0(scan(,''),'uffalo buffalo'))
B
B
b
B

Try it online!

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

C (gcc), 60 bytes

f(n){for(n=8;n--;)printf("%cuffalo%*.s","bBbbbBbB"[n],!!n);}

Try it online!

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

Pascal, 84 B

This program complies to ISO standard 7185 “Pascal” (level 0 sufficient):

program p(output);const s='uffalo buffalo B';begin write('B',s,s:15,'b',s,s:14)end.
\$\endgroup\$
1
\$\begingroup\$

Japt -S, 16 bytes

#¢ìbpu)m+"uffalo

Test it

#¢ìbpu)m+"uffalo
#¢                   :162
  ì                  :To digit array in base
   b                 :   Literal "b"
    p                :   Append
     u               :     Uppercase
      )              :End base conversion
       m             :Map
        +"uffalo     :  Concatenate "uffalo"
                     :Implicit output joined with spaces
\$\endgroup\$
1
\$\begingroup\$

C#, 70 bytes

Console.Write(string.Join("uffalo ","BbBbbbBb ".ToCharArray())[..^2]);

Try it online!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ This is in reverse order (Should be BbBbbbBb), and includes a leading space in the output \$\endgroup\$
    – Mayube
    Commented Nov 22 at 14:13
  • \$\begingroup\$ @Mayube Fixed :) \$\endgroup\$
    – Ezlanding
    Commented Nov 22 at 14:40
1
\$\begingroup\$

Vyxal 3 -S, 14 bytes

162bƛ"Tᶪэd„n¿V

Vyxal It Online!

Similar to vyxal 2, but with a better set up

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

Vyxal S, 11 10 bytes

⁺=bƛ‛ḋ¤nßǐ

Try it Online!

-1 byte thanks to pacman256

Explained (old)

⁺>bƛḃ‛ḋ¤$ßǐ
⁺>           # Push 163
  b          # and convert it to binary
   ƛ         # for each digit:
    ḃ        #   push whether the digit is "truthy"
     ‛ḋ¤     #   and push the string "buffalo"
        $    #   swap those two values
         ßǐ  #   and if the digit actually is truth, title case it
\$\endgroup\$
8
  • 1
    \$\begingroup\$ I like the answer, but you added the S flag after I posted my answer. You also slightly modified the behavior of Ɓ (seems to be virtually identical to me, but who knows). So sorry, no brownie points. \$\endgroup\$
    – Makonede
    Commented Feb 24, 2021 at 2:56
  • \$\begingroup\$ Wow you actually checked the interpreter and understood it. The Ɓ was changed to act like 05ab1e does (i.e. Handle the string "0" as falsey). It acts as a shortening of 0=0= \$\endgroup\$
    – lyxal
    Commented Feb 24, 2021 at 3:03
  • \$\begingroup\$ Ah ok. I was a bit confused when I saw that "compare" function there, but decided not to waste time trying to look for its definition. But yeah, I thought it was a bit suspicious, so I checked the interpreter and sure enough you just added the S flag. \$\endgroup\$
    – Makonede
    Commented Feb 24, 2021 at 3:06
  • 1
    \$\begingroup\$ Note to self: obfuscate flags \$\endgroup\$
    – lyxal
    Commented Feb 24, 2021 at 3:09
  • \$\begingroup\$ Python is my main language so it probably won't be too effective. Lol \$\endgroup\$
    – Makonede
    Commented Feb 24, 2021 at 3:10
0
\$\begingroup\$

JavaScript ES6, 51 bytes

(c=n=>n?c(n>>1)+'bB'[n&1]+'uffalo ':'')(162).trim()

Made sure to trim a trailing space. If we don't trim it, we get 44 bytes (but of course that violates the problem description).

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

C (gcc), 62 bytes (using binary properties)

n=8;f(){while(n--)printf("%cuffalo%c",98^(n==3^n&1)<<5,9+!n);}

Explanations:

  • 98 is 'b'
  • If we clear bit 1<<5 (32) from 'b' we obtain 'B': 'b' ^ (1 << 5) = 'B'). This property is true for all letters.
  • We want to clear this bit when n = 7, 5 and 1, which means when n is odd: n&1 with the exception iteration: 3 n==3^
  • 9+!n allows to have spaces (horizontal tab) except when n == 0: !n, then this expression will equal to 10 which is a new line return '\n'.
  • When n == 0 the while(n--) loop will automatically stops.

Try it online!

Thanks to caird coinheringaahing for catching the superfluous extra newline ;)

\$\endgroup\$
4
  • 1
    \$\begingroup\$ Welcome to the site and nice first answer! You can remove a byte by removing the final newline (Try it online!) and be sure to check out our Tips for golfing in C page for more golfing tips \$\endgroup\$ Commented Feb 10, 2021 at 19:21
  • \$\begingroup\$ Thanks I will take a look, I removed the '\n' that wasn't even showing up in the formula! \$\endgroup\$ Commented Feb 10, 2021 at 19:35
  • \$\begingroup\$ Can't be called twice \$\endgroup\$
    – l4m2
    Commented Mar 17, 2021 at 10:19
  • \$\begingroup\$ This is code golf, if you want to use it as a function then you just have to move n = 8 inside the function f and add int in front of it. It's purposely outside of the function to save 4 bytes (int + space). \$\endgroup\$ Commented Mar 17, 2021 at 14:37
0
\$\begingroup\$

StupidStackLanguage, 89 84 bytes

avvqmddlblbqaviqvmlblblqqqaviqvmlblblaviqvmlblbtfavvdqvdmfwwwffwfvvifiiifbvvvvdfbbbu

Try it online!

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

VBScript, 68 bytes

s="'BbBbbbBb'":k=""
For i=1 To Len(s)
k=k&Mid(s,i,1)&"uffalo "
Next 
\$\endgroup\$
1
  • \$\begingroup\$ 67 bytes ;-) k="Buffalo buffalo Buffalo buffalo buffalo buffalo Buffalo buffalo" \$\endgroup\$
    – jdt
    Commented Nov 2, 2022 at 13:02
0
\$\begingroup\$

BRASCA, 30 bytes

`bBbbbBbB`[o` olaffu`7[aoA{]x]

Try it

Explanation

`bBbbbBbB`                     - Push the first letters of each [Bb]uffalo
          [                  ] - While non-zero: 
           o                   -   Output the b/B
            ` olaffu`          -   Push "uffalo "
                     7[aoA{]x  -   Output it and clean up the counter
\$\endgroup\$
0
\$\begingroup\$

Excel, 49 bytes

=TEXTJOIN(" ",,CHAR(98-{4;4;0;4}*{8,0})&"uffalo")

Explanation

98-{4;4;0;4}*{8,0} =>  66 98 CHAR()=> B b
                       66 98          B b
                       98 98          b b
                       66 98          B b

Shortest Alternative, 51 bytes

=TEXTJOIN(" ",,MID("BbBbbbBb",ROW(1:8),1)&"uffalo")
\$\endgroup\$
0
\$\begingroup\$

Julia 1.0, 38 bytes

show(join(["BbBbbbBb"...].*"uffalo "))

Try it online!

\$\endgroup\$
1
  • \$\begingroup\$ This solution prints a trailing space. Removing the space from the base string and passing it as the separator argument only adds 3 bytes. \$\endgroup\$ Commented Sep 21, 2023 at 13:49
0
\$\begingroup\$

Knight (v2), 30 bytes

O S^+@'BbBbbbBb.''uffalo '63T@

Try it online!

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

JavaScript (Node.js), 47 46 bytes

_=>'B b B b b b B b'.replace(/b/gi,'$&uffalo')

Try it online!

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

Uiua, 25 23 bytes

↘2/$"_ _uffalo"⍥¯⋯372@B

Try it!

Take the binary digits of 372, making a B lowercase where there are ones. Reduce by inserting a space between and appending "uffalo", then drop the first two characters.

uses little-endian binary, so instead of using 162, I'd use 186. However because I combined steps of the joining by spaces and appending "uffalo" into one step, the first character ends up without the "uffalo" and just has to be removed. To fix this, I prepended an extra 0 to the binary representation to get 372, and just drop the first two characters of the result.

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

Kakoune, 24 bytes

8+iBuffalo <esc>b)<a-,>)<a-,>3)<a-,>`gld

basically we write Buffalo with 8 cursors then remove the selections we want to keep capitalized, then lowercase the rest

<a-,> = alt+comma

  • 8+ duplicate cursor 8 times
  • iBuffalo <esc> write Buffalo with each of the cursors
  • b move back and select words
  • )<a-,>)<a-,> rotate main selection forwards then remove main selection (repeated twice)
  • 3)<a-,> rotate main selection 3 times forwards then remove main selection
  • ` lowercase remaining selections
  • gld go to end and delete trailing space
\$\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.