My colleague recently sent me the following piece of JavaScript as a joke:

let butScript = (nrOfButs) => {
    for(var i = 0; i < nrOfButs; i++){
        if(i % 3 == 0){
        if(i % 2 == 0){
        if(i % 3 == 1){

Since the code was written during work hours, it was obviously a huge waste of company resources. To prevent similar occurrences in the future, we must minimize the waste of worked hours. And since it is common knowledge that a shorter program is faster to write, we must golf this code to be as short as possible!


A single non-negative integer. You must not handle faulty input.


Your program must produce output identical to that of the script above. You should output one word per line, and the number of words should be consistent with the original script.

It is permissible to include non-newline whitespace characters at the end of each line (but not at the beginning) since they are invisible. One additional newline character is permissible at the very end of the output.


Input: 0

Input: 1

Input: 2

Input: 10
  • 3
    Can we return a list of lines? – Jo King Sep 12 at 8:20
  • 10
    It must entertaining to work with such a funny chap! :s On a slightly more serious note: the nrOfButs variable is rather poorly-named and misleading. Nice simple challenge anyway. – Arnauld Sep 12 at 9:54
  • 10
    Do we get a bonus if the last line is "God can't believe you just said that!" – Ciaran_McCarthy Sep 12 at 10:24
  • 3
    @EriktheOutgolfer the ifs fall trough and continue in the current loop if their condition was satisfied. – dzaima Sep 12 at 15:35
  • 4
    The most Australian codegolf yet? Except it should be "nah" – Nacht Sep 13 at 2:00

38 Answers 38

Excel, 78 bytes

Assumes input in cell A1, and that Wordwrap formatting is turned on for cell. Use Alt+Enter to add line feeds within the string and note the whitespace. Only handles input up to 3570 due to limit of REPT function (Good luck getting a cell to be that tall, though).


Reprinting, with periods for whitespace


How it works: The pattern repeats every 6 numbers:

0 = Yeah and But      Yeah + linefeed + But + linefeed
1 = No                No + 6 whitespace + line feed
2 = But               But + 5 whitespace + linefeed
3 = Yeah              Yeah + 4 whitespace + linefeed
4 = But and No        But + linefeed + No + 3 whitespace
5 = Blank             8 whitespace + linefeed

Each of these can be expressed with 9 characters, so a string is made of 54 characters (9 * 6), then repeated as large as Excel will allow. Then it takes the left 9 * (number of input) characters as the output.

Linefeed for the "but and no" one is placed after the blank so that the Yeah for #6, #12, (etc) is formatted to the left rather than the right, and so that there is no blank linefeed added every 6th line for that item.


  • 1
    I have no way of verifying this, but your description makes it seem correct. Can you add some example input/output pairs? One of the more ridiculous languages, but great answer nonetheless. – maxb Sep 12 at 14:09
  • 16
    @maxb Can't be all that ridiculous when it is beating other languages. – Keeta Sep 12 at 14:21
  • 1
    Great explanation and very cool technique. Works in LibreOffice Calc as well but might need some playing with the formatting. +1 – ElPedro Sep 12 at 17:32

JavaScript (ES6), 59 57 bytes


Try it online!


We use a recursive function which goes from \$n\$ to \$1\$ rather than from \$0\$ to \$n-1\$.

As a result, the tests are off by \$1\$ compared to the reference code:

  • if \$n\equiv1\pmod 3\$, output "Yeah"
  • if \$n\equiv1\pmod 2\$, output "But"
  • if \$n\equiv2\pmod 3\$, output "No"

This allows us to store the simpler case \$n\equiv0\pmod 3\$ as the first entry of our lookup array, where we can define \$s\$: a variable holding either "But\n" or an empty string.

The two other entries are defined as "Yeah\n" + s and s + "No\n" respectively.

Note: By iterating from \$n-1\$ to \$0\$, we could define \$s\$ in the first entry just as well, but that would cost two extra parentheses.


f = n =>            // n = input
  n ?               // if n is not equal to 0:
    f(n - 1) +      //   prepend the result of a recursive call with n - 1
    [               //   define our lookup array:
      s = n & 1 ?   //     1st entry: if n is odd:
        `But\n`     //       set s to "But"
      :             //     else:
        '',         //       set s to an empty string
      `Yeah\n` + s, //     2nd entry: "Yeah" followed by s
      s + `No\n`    //     3rd entry: s followed by "No"
    ][n % 3]        //   append the correct entry for this iteration
  :                 // else:
    ''              //   return an empty string and stop recursion

LOLCODE, 257 bytes

HAI 1.2

Try it online!

  • 2
    It looks awesome (I would hate to code this!), but in test case 10 the 2nd "No" and 3rd "But" get flipped... So Yeah, but no :D – seadoggie01 Sep 13 at 3:23
  • 2
    Whoops, thought I could optimize there. This is a tricky pattern. I fixed it now. – JosiahRyanW Sep 13 at 6:45
  • 1
    I love the way it reads – LocustHorde Sep 13 at 15:51
  • 4
    Does VISIBLE "But" refer to the program's lack of trousers? – JDL Sep 14 at 14:03

Whitespace, 315 304 300 277 276 bytes

Thanks to @JoKing for -11 bytes (reducing the amount of labels used from 8 to 7), and -24 more bytes (changing the general flow of the program and reducing the amount of labels used from 7 to 5 in the process).

[S S S N
_Push_0][T  N
T   T   _Read_STDIN_as_integer][N
_Create_Label_LOOP][S S S N
_Push_0][T  T   T   _Retrieve][N
T   S S N
_If_negative_jump_to_Label_PRINT][S S S N
_Push_0][T  T   T   _Retrieve][S S S T  T   N
_Push_3][T  S T T   _Modulo][S S S T    S N
_Push_2][T  S S T   _Subtract][N
T   T   T   N
_If_negative_jump_to_Label_SKIP_NO][S S T   T   S T T   T   T   S N
_Push_-94_\n][S S S T   T   T   N
_Push_7_o][S S T    T   T   S T S N
S S T   N
_Create_Label_SKIP_NO][S S S N
_Push_0][T  T   T   _Retrieve][S S S T  S N
_Push_2][T  S T T   _Modulo][N
T   S S S N
_If_0_jump_to_Label_SKIP_BUT][S S T T   S T T   T   T   S N
_Push_-94_\n][S S S T   T   S S N
_Push_12_t][S S S T T   S T N
_Push_13_u][S S T   T   S S T   T   S N
_Create_Label_RETURN_FROM_BUT][S S S N
_Push_0][S N
S _Duplicate_0][S N
S _Duplicate_0][T   T   T   _Retrieve][S S S T  N
_Push_1][T  S S T   _Subtract][T    T   S _Store][T T   T   _Retrieve][S S S T  T   N
_Push_3][T  S T T   _Modulo][N
T   S S T   N
_Create_Label_YEAH][S S T   T   S T T   T   T   S N
_Push_-94_\n][S S S N
_Push_0_h][S S T    T   T   T   N
_Push_-7_a][S S T   T   T   N
_Push_-3_e][S S T   T   T   T   T   N
_Create_Label_PRINT][S S S T    T   S T S S S N
_Push_104][T    S S S _Add][T   N
S S _Print_as_character][N

Letters S (space), T (tab), and N (new-line) added as highlighting only.
[..._some_action] added as explanation only.

Try it online (with raw spaces, tabs and new-lines only).

Whitespace is definitely not the right language for this challenge.. In Whitespace both loops and if-statements are made with labels and jumps to labels, and since they aren't if-elseif-else cases but multiple if-cases, it means I will have to jump back after every if, making it quite long it means I will have to slightly modify the checks to skip over some prints (thanks @JoKing).

Explanation in pseudo-code:

Read STDIN as integer, and store it in the heap
Start LOOP:
  Integer i = retrieve integer from heap
  If(i is negative):
    Call function PRINT
  If(i modulo-3 is NOT 2):
    Jump to Label SKIP_NO
  Push "\noN" to the stack
  Label: SKIP_NO
  If(i modulo-2 is 0):
    Jump to Label SKIP_BUT
  Push "\ntuB" to the stack
  Label: SKIP_BUT
  i = i - 1
  Replace i in the heap with this updated value
  If(i modulo-3 is 0):
    Call function YEAH
  Go to next iteration of LOOP

function YEAH:
  Push "\nhaeY" to the stack
  Go to next iteration of LOOP

function PRINT:
  Print top of the stack as character to STDOUT
  Go to next iteration of LOOP (which will enter the if and then
                                comes back to this PRINT again)

Additional explanation:

In general, it loops from the input down to 0, pushing a newline and the word reversed (so in the order "\noN", "\ntuB", "\nhaeY" instead of "Yeah\n", "But\n", "No\n"). And after the input has looped down to 0 and all the characters are on the stack, it will print those characters in reverse (so the correct output order).

More in depth however: Although we need to print words in the range (input, 0], it will loop in the range [input, 0) instead. Because of this, we can use the check if(i%3 == 2) for "\noN" (or actually, if(i%3 != 2) skip the pushing of "\noN"), and we use the check if(i%2 != 1) for "\ntuB" (or actually, if(i%2 == 0) skip the pushing of "\ntuB"). Only after these two checks we decrease the iteration i by 1. And then do the check if(i%3 == 0) to push "\nhaeY", similar as in the JS example code in the challenge description. Skipping with if-not checks instead of going to a label and return from the label with if-checks saved 23 bytes.

Also, in Whitespace character values are stored in the stack as their unicode values (i.e. 10 for new-lines, 65 for 'A', 97 for 'a', etc.). Since I already need to loop over the stack to print the characters, I am also able to use my Whitespace tip to lower the byte-count by adding a constant to the number values, before printing them as characters.
This constant is 104 in this case, which is generated with this Java program that I've also used to golf another Whitespace answer of mine before. That's also the reason why this part of the code:

[S S T  T   S T T   T   T   S N
_Push_-94_\n][S S S T   T   T   N
_Push_7_o][S S T    T   T   S T S N

has the values -94 for the newline, 7 for the 'o', and -26 for the 'N'. Because adding the constant of 104 will correctly give our unicode values 10, 111, and 78 for these characters respectively.

  • 1
    I most certainly did not expect a Whitespace answer. Good job! – maxb Sep 12 at 12:31
  • @maxb Thanks! Unfortunately it's quite a bit longer than expected due to the 8 labels it requires.. But I'm already happy it's working. :) – Kevin Cruijssen Sep 12 at 12:37
  • Couldn't you halve the labels by skipping to the next if statement if the condition is false? e.g. if i modulo-3 != 1 jump to next if else push NO – Jo King Sep 12 at 13:15
  • 1
    @JoKing Ah wait, I misunderstood a part of your pseudo-code. My first issue about not retrieving i before the if(i is 0) call PRINT is true, but your other is checking the i before subtracting it and skipping over the prints. Pretty smart actually. Will continue implementing it. – Kevin Cruijssen Sep 13 at 10:00
  • 1
    Well, if you jump to the start of the loop, it will run the if statement again and jump straight back to the print function. Maybe this saves a byte if you change the loop label to the empty label – Jo King Sep 13 at 12:40

Python 3, 85 82 bytes

def f(n):
 for i in range(n):yield from['Yeah'][i%3:]+['But'][i%2:]+['No'][i%3^1:]

Try it online!

Python 3, 79 76 bytes

Port of Keeta's Excel answer.

lambda n:(f"""Yeah

Try it online!

Perl 6, 63 50 bytes

{<<"Yeah But"No But Yeah"But No">>[^$_ X%6].words}

Try it online!

Anonymous code block that takes a number and returns a list of lines


{                                                }   # Anonymous code block
 <<"Yeah But"No But Yeah"But No">>  # Create the list of strings:
                                     # Yeah But
                                     # No
                                     # But
                                     # Yeah
                                     # But No
                                  [       ]  # Index into this list
                                   ^$_  # The range from 0 to n-1
                                       X%6  # All modulo 6
                                           .words  # Convert the list to a string 
                                                   # Which joins by spaces
                                                   # And split by whitespace

C (gcc), 75 bytes


Try it online!

C (gcc), 60 + 11 = 71 bytes (using -D$=||puts()

f(o,_){for(_=0;o-_;_++%3-1 $"No"))_%3 $"Yeah"),1&_ $"But");}

Try it online!

05AB1E (legacy), 27 25 24 bytes

Saved 1 byte thanks to Kevin Cruijssen.


Try it online!


F                          # for N in [0 ... input] do:
 ”¥æ€³€¸”#                 # push ['Yeah', 'But', 'No']
          N3Ö              # push N % 3 == 0
             NÈ            # push N % 2 == 0
               N3%         # push N % 3
                  ‚‚˜      # add the 3 numbers to a list
                     Ï     # keep only the strings whose corresponding value  
                           # in the int list is true (1)
                      `»   # push strings separately to stack and join stack on newlines
  • Dang, you beat me to it.. Was about to post an answer. Yours is shorter anyway, so +1 from me.. Nice use of ×, hadn't thought about that! – Kevin Cruijssen Sep 12 at 8:27
  • Wow, I'd love an explanation on this one. My personal best was 44 bytes in CJam. – maxb Sep 12 at 8:29
  • @maxb: I will of course add an explanation. I'm just checking to see if I can golf it down some more first ;) – Emigna Sep 12 at 8:30
  • You can remove the Θ now that you're no longer using ×, since Ï will only look at 1s only, so it ignores the 2 (and 0 of course). – Kevin Cruijssen Sep 12 at 9:32
  • @KevinCruijssen: Thanks! Not sure how I missed that :P – Emigna Sep 12 at 9:51

Python 2, 73 bytes

lambda n:'\n'.join((["Yeah\nBut","No","But","Yeah","But\nNo"]*n)[:n-n/6])

Try it online!

Python 2, 97 95 92 90 83 81 bytes

lambda n:[w for i in range(n)for w in'Yeah','But','No'if('N'in w)==i%(3-(w<'N'))]

Try it online!

-2 bytes, thanks to ovs

Python 3, 92 90 85 83 bytes

lambda n:[w for i in range(n)for w in['Yeah','But','No']if('N'in w)==i%(3-(w<'N'))]

Try it online!

-4 bytes, thanks to ovs

-4 bytes, thanks to Jo King

  • 86 bytes by combining the two and returning as a list of lines – Jo King Sep 12 at 13:09
  • @JoKing Thanks, didn't know that I could return instead of printing when wrote it. – TFeld Sep 12 at 13:14
  • 82 bytes: len(w)<3 -> 'N'in w, 81 bytes : len(w)%2 -> (w<'N') – ovs Sep 12 at 13:22
  • @ovs Thanks, :) – TFeld Sep 12 at 13:27

Groovy (function), 79 bytes

Since initially submitting my answer, I've looked through some historic discussions here about what constitutes a suitable answer. Since it seems commonly accepted to provide just a method in Java (including return type and parameter declarations), here is a shorter, Groovy, method which has the method return value be the answer. Use of def means that the return type is inferred.

def a(int n){n?a(--n)+(n%3?'':'Yeah\n')+(n%2?'':'But\n')+(n%3==1?'No\n':''):''}

Unlike the original answer below, which loops from 0 up to n-1, this one calls itself from n down to 1, but decrements the input for the rest of the line in the recursive call.

Try it online!

Groovy (program), 87 bytes

Groovy scripts don't require certain common imports, so this can be a program printing the answer to Java's STDOUT without having to declare System.out. before print. It also provides some common utility methods, such as this toLong() which allows us to parse the input argument reasonably consicely.

Essentially the Java 10 answer, but leveraging Groovy's shorter loop syntax and ability to evaluate truthy statements.


Try it online!

  • Welcome to PPCG! Great first answer! I haven't coded any Groovy myself, but might I suggest running your code on TIO? That way, it can be validated by others, and enjoyed by all. – maxb Sep 12 at 15:20
  • 1
    @maxb Thanks! I've added one :) – archangel.mjj Sep 12 at 15:29
  • Nice first answer and also welcome to PPCG. – ElPedro Sep 12 at 18:03

Retina 0.8.2, 45 bytes



Try it online! Explanation:


Convert the input to unary.


For each integer 0...n-1, generate three lines of text, one for each word, each with i 1s before it, except for No, which has two extra 1s so that we calculate (i+2)%3==0 which is equivalent to i%3==1.


Remove pairs of 1s before Bs.


Remove 1s in groups of three everywhere else.


Delete all lines that still have a 1.

  • Oh, now that I see 11No¶ to calculate (i+2)%3==0 (so all three are if-checks for ==0) it looks so obvious, but I wouldn't have thought of that myself, so it's actually quite ingenious. +1 from me, nice answer! – Kevin Cruijssen Sep 12 at 12:51

Canvas, 27 bytes


Try it here!

Java 10, 100 99 bytes

n->{for(int i=0;i<n;)System.out.print((i%3<1?"Yeah\n":"")+(i%2<1?"But\n":"")+(++i%3>1?"No\n":""));}

-1 byte thanks to @OlivierGrégoire.

Try it online.


n->{                   // Method with integer parameter and no return-type
  for(int i=0;i<n;)    //  Loop `i` in the range [0, `n`)
    System.out.print(  //   Print to STDOUT:
      (i%3<1?          //    If `i` is divisible by 3:
        "Yeah\n"       //     Print "Yeah" with newline
      :"")+(i%2<1?     //    If `i` is even:
        "But\n"        //     Print "But" with newline
      :"")+(++i%3>1?   //    If `i` modulo-3 is 1:
        "No\n"         //     Print "No" with newline
      :                //    If none of the above three if's applied to the current `i`:
       ""));}          //     Print nothing for the current `i`

Powershell, 75 74 72 67 66 bytes

-1 byte thanks TessellatingHeckler

param($n)(" Yeah
But No But Yeah But
No "*$n-split' ')[1..$n]-ne''

Test script and explanation:

$f = {

param($n)(" Yeah
But No But Yeah But
No "*$n-split' ')[1..$n]-ne''

# 1. repeat the string $n times
# 2. split by space
# 3. get elements from 1 to $n
# some elements are multiline strings, some elements are $null:
# ($null,"Yeah`nBut","But","No","But","Yeah","But`nNo",$null,...)
# 4. remove $null elements from result array


# Output results
) | % {
    &$f $_

# Advanced test
    ,(1,'Yeah But')
    ,(2,'Yeah But No')
    ,(3,'Yeah But No But')
    ,(4,'Yeah But No But Yeah')
    ,(5,'Yeah But No But Yeah But No')
    ,(6,'Yeah But No But Yeah But No')
    ,(7,'Yeah But No But Yeah But No Yeah But')
    ,(8,'Yeah But No But Yeah But No Yeah But No')
    ,(9,'Yeah But No But Yeah But No Yeah But No But')
    ,(10,'Yeah But No But Yeah But No Yeah But No But Yeah')
    ,(20,'Yeah But No But Yeah But No Yeah But No But Yeah But No Yeah But No But Yeah But No Yeah But No')
) | % {
    $n,$e = $_
    $r = &$f $n
    $r = $r-split"`n"       # simplify test string
    "$($e-eq$r): $n : $r"


True: 0 :
True: 1 : Yeah But
True: 2 : Yeah But No
True: 3 : Yeah But No But
True: 4 : Yeah But No But Yeah
True: 5 : Yeah But No But Yeah But No
True: 6 : Yeah But No But Yeah But No
True: 7 : Yeah But No But Yeah But No Yeah But
True: 8 : Yeah But No But Yeah But No Yeah But No
True: 9 : Yeah But No But Yeah But No Yeah But No But
True: 10 : Yeah But No But Yeah But No Yeah But No But Yeah
True: 20 : Yeah But No But Yeah But No Yeah But No But Yeah But No Yeah But No But Yeah But No Yeah But No

Straightforward script, 72 bytes:

  • 1
    Great answer! Would it be possible to add some output to the answer, since it doesn't include an online interpreter? – maxb Sep 12 at 13:36
  • The answer scriptblock does not return ======. It generates Yeah,But,No strings only. The test script shows a separator for easier reading of the results only. – mazzy Sep 12 at 14:10
  • That hashtable usage is clever. I'm going to need to remember that. – AdmBorkBork Sep 12 at 18:35
  • 1
    @mazzy I can reformulate yours, but still can't beat 67 (replace the two \n with real newlines) (" Yeah\nBut No But Yeah But\nNo "*($j="$args")|% s*t 32)[1..$j]-ne'' – TessellatingHeckler Sep 17 at 5:49

Haskell, 71 bytes

f n=[1..n]>>=(3?1)"Yeah"<>(2?1)"But"<>(3?2)"No"
(a?b)c n=[c|n`mod`a==b]

Try it online!


Pretty simple, saved two bytes by using [1..n] instead of [0..n-1] and adjusted the remainders: The operator (?) tests takes four arguments, returning an empty list or the provided string as a singleton if the result is correct.

By currying the fourth argument of (?) we can make use of (<>) to concatenate the results of each function, ie.:

(3?1)"Yeah" <> (2?1)"But" <> (3?2)"No" ≡ \i-> (3?1)"Yeah" i ++ (2?1)"But" i ++ (3?2)"No" i

C# (Visual C# Interactive Compiler), 105 99 94 96 89bytes

i=>{for(int x=0;x<i;)Write((x%3<1?"Yeah\n":"")+(x%2<1?"But\n":"")+(x++%3==1?"No\n":""));}

Try it online!

  • 4
    Removing the interpolation like this saves 7 bytes. – Emigna Sep 12 at 10:43
  • @Emigna Thanks for the tip, changed the answer – auhmaan Sep 12 at 16:33
  • 1
    x++%3==1? can be ++x%3>1?. Someone else just tipped it for my Java answer, but the same applies to your C# answer. :) – Kevin Cruijssen Sep 13 at 7:41

Pip, 37 35 33 bytes


(Note the space after But.) Takes input as a command-line argument. Try it online!


This explanation is for the previous version--see below for changelog

Inspired by Jo King's Perl 6 answer. We construct this list:


and output the first a elements of it using cyclic indexing.

                                     i is 0; o is 1; t is 10; x is ""; n is newline;
                                     a is 1st cmdline arg (implicit)
[       ]                            Construct this list of scalars:
 t                                    10
  2                                   2
   i                                  0
    o                                 1
     02                               02
       x                              <empty string>
         R                           Treating each of these as a string, we're going to
          ,3                          0, 1, and 2 (respectively)
                                     with the corresponding values from this list:
            ["But""Yeah""No"].n       These strings, each with a newline appended
                                     We now have constructed the list shown above
                               @<:a  Take the first a elements from this list, with
                                     cyclical indexing (the : is for parsing reasons)
                                     Concatenate them together and print (implicit)

Update: I realized that I don't need to use replace to change 0/1/2 into strings--I can use those numbers to index into a list directly. To do this, we have to make sure the multi-digit numbers are split into lists of their digits (otherwise, we'll be selecting index 10 instead of indexes 1 and 0). Fortunately, using an arbitrarily nested list as an index in Pip works as expected, giving a (nested) list of results. For input of 3, we get this data progression (where _ represents a newline):

"But _Yeah_No_"<>5                       ["But _"; "Yeah_"; "No_"]
                     [t2io02x]           [10; 2; 0; 1; 02; ""]
                              @<a        [10; 2; 0]
                    ^                    [[1; 0]; [2]; [0]]
                  @:                     [["Yeah_"; "But _"]; ["No_"]; ["But _"]]

As before, the final result is concatenated together and autoprinted.

Attache, 48 bytes


Try it online!


Flat##{Mask[_%3'2'3=0'0'1,$Yeah'$But'$No]}=>Iota   input: an integer
      {                                  }=>Iota   over each number from 0 to that integer exclusive
       Mask[             ,$Yeah'$But'$No]          select values from that array according to:
            _%3'2'3                                    whether or not the input mod 3, 2, 3
                   =0'0'1                              is 0, 0, 1
Flat##                                             flatten the intermediate results

C (gcc), 77 71 74 72 69 bytes

There's already a better C answer here but this one is recursive and it took me some time to get straight so I'm posting it.

Down to 69 bytes thanks to both @ceilingcat and @JonathanFrech

(I never think to use n-~-i in place of n-i+1)


Try it online!

  • @JonathanFrech Nice but doesn't work for zero, or 5 – cleblanc Sep 18 at 17:04
  • @cleblanc Oh, sorry. Did not realize ... At least removing j saved you two bytes. – Jonathan Frech Sep 18 at 17:46
  • 1
    70 bytes -- incorporating @ceilingcat's one saved byte. – Jonathan Frech Sep 18 at 18:01
  • 1
    n-~-i is equivalent to n-i+1 -- not i<n+1 -- and so does not actually save any bytes ... – Jonathan Frech Sep 18 at 19:16

Ruby, 69 72 74 Bytes

->y{puts *(1..y).map{|i|[i%3==1&&:Yeah,i%2>0&&:But,i%3>1&&:No]-[!0]}}

Very straight-forward answer, checking for a shorter, recursive method right now.

Saved two bytes thanks to @BWO :)

Saved another three bytes by using symbols instead of strings

Python 3, 93 bytes

[print("Yeah\n"*(i%3<1)+"But\n"*(i%2<1)+"No\n"*(i%3==1),end="")for i in range(int(input()))]

This isn't exactly the best solution but it's my take on it.

Try it online!

  • 1
    If you already have an expression you can use in a list comprehension but your list comprehension only exists to evoke that expression's side effects, a plain for loop requires less bytes. – Jonathan Frech Sep 14 at 2:21

R, 65 bytes


Due to the fact that we are replicating a slightly flawed program (it misses out every fourth "but" — it should have used %4 == 1 and %4 == 3 rather than %3 conditions), we have to use an awkward call to c and work in base seven. Still, it's shorter than LOLCODE...

(I was hoping that (3,1,2,3,2,1,2) or a similar permutation might appear in the lh dataset somewhere but it doesn't look like it)

sed -E, 179 150 bytes


The hardest part was not to construct the list but to actually parse the decimal number.

2 bytes may be saved if the newline at the end is not required: c\ d.

Still requires optimization.

Try it online.


/^0/!                            | if the input number doesn`t begin with a '0'…
     s:$:g:                      | …then append a 'g' to it and proceed
:l;                              | loop label 'l':
   y:abcdefg:bcdefga:            | shift all occurences of [abcdef] 1 letter forward, and all 'g'-s to 'a'-s
/[ae]/                           | if there`s an 'a' or 'e' in the input…
      iYeah                      | …output 'Yeah'
/[bdf]/                          | if there`s a 'b' or 'd' or 'f' in the input…
       iBut                      | …output 'But'
/[cg]/                           | if there`s a 'c' or 'g' in the input…
      iNo                        | …output 'No' 
s:.$:-&:;                        | insert '-' before the last character
         :s;                     | loop label 's':
            s:0-:-9:;            | transform the next consecutive '0' in the end of the number to '9', if any
                     ts;         | loop to 's' if more consecutive zeroes are available
                        h        | copy the result to the temporary buffer
y:123456789:012345678:;          | decrement all digits except '0' (N.B.: digits, not numbers)
                       G         | append the temporary buffer to the result
s:.*(.)-.*\n(.*).-:\2\1:;        | cut and replace the digit left to the last consecutive 0 in the original
                                 | number pasted from the temporary buffer, then discard all other digits decremented
                         tl;     | …then loop to 'l' if the number is ≥0
                            c\   | insert a carriage return and exit
  • Can you add some explanations please ? – user285259 Sep 21 at 8:30
  • 1
    @user285259 Done. – hidefromkgb Sep 21 at 13:21

Clean, 116 bytes

import StdEnv,Data.List

Try it online!

F#, 108 106 bytes

let v p=seq{for i=1 to p do
 if i%3=1 then yield"Yeah"
 if i%2=1 then yield"But"
 if i%3=2 then yield"No"}

Try it online!

-2 bytes changing from i=0 to p-1 to i=1 to p and adjusting modulos. Apart from that, pretty straight-forward.

  • 1
    I get some kind of build error for the TIO link, perhaps a syntax error in the testing code? – maxb Sep 13 at 8:15
  • Thanks for that. My original solution printed directly to the console, but then I tried returning a sequence and it turned out to be shorter by about 2 bytes. So I changed the code in the TIO but forgot to update the footer - which was still expecting the v function to print everything out. – Ciaran_McCarthy Sep 13 at 8:36
  • 2
    Shave 2 bytes with i=1 to p (and adjusting moduli, naturally). Reverse ranges are empty. :) – user82031 Sep 13 at 18:16
  • Nice! I've added that. Thanks! :) – Ciaran_McCarthy Sep 13 at 20:56

PHP, 65 68 bytes


Run as pipe with -nR or try it online.

  • It looks good, but it produces an extra newline in the middle for n=10 – maxb Sep 13 at 21:02
  • @maxb Thanks for the hint. I could have fixed it with 9 extra bytes; but the other approach is shorter. – Titus Sep 13 at 23:50

VBA (Excel), 105, 101, 99 Bytes

Edit: -4 bytes from Keeta! Thanks!

Edit 2: -2 bytes from Chronocidal! Woot! (Realized that test cases only worked for 10. Fixed now)

Yeah, Excel beat VBA this time. Whatever. (We're coming for you)

d=vbCr:For i=1To[a1]:a=i Mod 3:?IIf(a=1,"Yeah"+d,"")IIf(i/2=i\2,"","But"+d)IIf(a=2,"No"+d,"");:Next

^This is pasted into the Immediate window and outputs to the debug window


d = vbCr
'For 1 to the value in A1 (using 0 gave extra values, and VBA skips the for loop if 0)
For i = 1 To [a1]    'aka: Range("A1").value
    a = i mod 3
    '? is the same as Print (Debug.Print when not in the Immediate Window)
    Print IIf(a = 1, "Yeah" + d, "") _ '<-- Just a line continuation
          'Keeta taught me that the \ operator is division with truncation,
          '     so if they are equal then there is no remainder!
          IIf(i / 2 = i \ 2, "", "But" + d) _
          IIf(a = 2, "No" + d, "");
    'Print usually prints a newline, but it still outputs if the string is blank...
    '   So we append a newline -if true- and use a semi-colon to kill the newline
  • @Keeta good idea, but no... If you look at my first code, I use [a1] which means Range/cell .value :) I should've made it more clear that was an explanation though, sorry :/ – seadoggie01 Sep 14 at 13:20
  • 1
    Yeah, I saw that and tried to delete the comment. How about using i/3=i\3 instead of i mod 3 = 0 (and same for mod 2 = 0). Haven't tried it, but would it work? – Keeta Sep 14 at 13:24
  • @Keeta I've never seen the \ operator before... I don't think so though, it returns the value of division without the remainder... like the opposite of Mod I think – seadoggie01 Sep 14 at 13:28
  • One is integer division and one is floating point. 7/3 = 2.3333 where 7\3 = 2 (truncate division). 6/3 should be 2, and 6\3 should also be 2 so it should work whenever remainder is zero (I think). – Keeta Sep 14 at 13:30
  • 1
    VBA will automatically concatenate function outputs, so you can drop the & between eachIIf(..) for an extra 2 bytes – Chronocidal Sep 14 at 15:40

Jelly, 22 bytes


A monadic Link yielding a list of lines (which seems to have been allowed in comments)

Try it online! (the footer calls the Link using Ç and joins with newlines using Y since implicit printing in Jelly smashes everything together if it can)


First note that we have a period of \$2\times3=6\$ due to the modulo definition.

Now note that the first six values are:

["Yeah", "But"]
["But", "No"]

So the resulting list of lines should be these values repeated (or truncated) to length n concatenated together.

Now note that the power-set of "Yeah", "But", "No" is:

["Yeah", "But"]
["Yeah", "No"]
["But", "No"]
["Yeah", "But", "No"]

So each period is these 1-indexed values of the power-set of "Yeah", "But", "No":

5, 4, 3, 2, 7, 1

The code makes this list, moulds it to length n, indexes into the power-set, and then removes the inner lists (which also removes the empty strings, since strings are lists in Jelly)...

5Rż7FṚṁị“'⁴\ÆẓNƇ»ḲŒP¤Ẏ - Link: integer, n   e.g. 10
5                      - literal five            5
 R                     - range                   [1,2,3,4,5]
   7                   - literal seven           7
  ż                    - zip together            [[1,7],[2],[3],[4],[5]]
    F                  - flatten                 [1,7,2,3,4,5]
     Ṛ                 - reverse                 [5,4,3,2,7,1]
      ṁ                - mould like (n)          [5,4,3,2,7,1,5,4,3,2]
                    ¤  - nilad followed by link(s) as a nilad:
        “'⁴\ÆẓNƇ»      -   compressed string     "Yeah But No"
                 Ḳ     -   split at spaces       ["Yeah","But","No"]
                  ŒP   -   power-set             [[],["Yeah"],["But"],["No"],["Yeah","But"],["Yeah","No"],["But","No"],["Yeah","But","No"]]
       ị               - index into              [["Yeah","But"],["No"],["But"],["Yeah"],["But","No"],[],["Yeah","But"],["No"],["But"],["Yeah"]]
                     Ẏ - tighten                 ["Yeah","But","No","But","Yeah","But","No","Yeah","But","No","But","Yeah"]
  • I doubt it's going to get any shorter than this. Fantastic answer, and a great explanation, well done! – maxb Sep 17 at 5:01

Python 2, 93 92 83 bytes

lambda i:''.join('Yeah\n'*(x%3<1)+'But\n'*(x%2<1)+'No\n'*(x%3==1)for x in range(i))

Try it online!

A massive 9 bytes saved with thanks to @Jonathan Frech

  • You could use string repetition instead of tuple indexing -- ('','Yeah\n')[x%3<1] is equivalent to "Yeah\n"*(x%3<1). – Jonathan Frech Sep 16 at 10:34
  • @JonathanFrech - very cool! Similar technique can be applied to the other cases as well. Many thanks! – ElPedro Sep 17 at 8:10

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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