# Yeah But No But Yeah

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){
console.log("Yeah")
}
if(i % 2 == 0){
console.log("But")
}
if(i % 3 == 1){
console.log("No")
}
}
}


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!

## Input

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

## Output

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.

## Examples

Input: 0
Output:

Input: 1
Output:
Yeah
But

Input: 2
Output:
Yeah
But
No

Input: 10
Output:
Yeah
But
No
But
Yeah
But
No
Yeah
But
No
But
Yeah

• Can we return a list of lines? – Jo King Sep 12 '18 at 8:20
• 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 '18 at 9:54
• Do we get a bonus if the last line is "God can't believe you just said that!" – Ciaran_McCarthy Sep 12 '18 at 10:24
• @EriktheOutgolfer the ifs fall trough and continue in the current loop if their condition was satisfied. – dzaima Sep 12 '18 at 15:35
• The most Australian codegolf yet? Except it should be "nah" – Nacht Sep 13 '18 at 2:00

# 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).

=LEFT(REPT("Yeah
But
No
But
Yeah
But
No
",595),A1*9)


Reprinting, with periods for whitespace

=LEFT(REPT("Yeah
But
No......
But.....
Yeah....
But
No...........
",595),A1*9)


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.

• 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 '18 at 14:09
• @maxb Can't be all that ridiculous when it is beating other languages. – Keeta - reinstate Monica Sep 12 '18 at 14:21
• Great explanation and very cool technique. Works in LibreOffice Calc as well but might need some playing with the formatting. +1 – ElPedro Sep 12 '18 at 17:32

# JavaScript (ES6), 59 57 bytes

f=n=>n?f(n-1)+[s=n&1?But
:'',Yeah
+s,s+No
][n%3]:''


Try it online!

### How?

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.

### Commented

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
I HAS A B
GIMMEH B
B IS NOW A NUMBR
I HAS A C ITZ 0
IM IN YR L UPPIN YR C TIL BOTH SAEM B AN C
I HAS A D ITZ MOD OF C AN 3
D
WTF?
OMG 0
VISIBLE "Yeah"
OIC
MOD OF C AN 2
WTF?
OMG 0
VISIBLE "But"
OIC
D
WTF?
OMG 1
VISIBLE "No"
OIC
IM OUTTA YR L
KTHXBYE


Try it online!

• 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 '18 at 3:23
• Whoops, thought I could optimize there. This is a tricky pattern. I fixed it now. – JosiahRyanW Sep 13 '18 at 6:45
• I love the way it reads – LocustHorde Sep 13 '18 at 15:51
• Does VISIBLE "But" refer to the program's lack of trousers? – JDL Sep 14 '18 at 14:03

# Whitespace, 315304300277 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
S S 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
_Push_-26_N][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
_Push_-38_B][N
S S S 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
_If_0_jump_to_Label_YEAH][N
S N
N
_Jump_to_Label_LOOP][N
S 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
_Push_-15_Y][N
S N
N
_Jump_to_Label_LOOP][N
S S S 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
S N
N
_Jump_to_Label_LOOP]


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):
Push "\noN" to the stack
Label: SKIP_NO
If(i modulo-2 is 0):
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)


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
_Push_-26_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.

• I most certainly did not expect a Whitespace answer. Good job! – maxb Sep 12 '18 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 '18 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 '18 at 13:15
• @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 '18 at 10:00
• 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 '18 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

lambda n:(f"""Yeah
But
No
But
Yeah
But
No{'':11}
"""*n)[:9*n]


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 ### Explanation: { } # 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

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


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), 2725 24 bytes

Saved 1 byte thanks to Kevin Cruijssen.

F”¥æ€³€¸”#N3ÖNÈN3%‚‚˜Ï»


Try it online!

Explanation

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 '18 at 8:27
• Wow, I'd love an explanation on this one. My personal best was 44 bytes in CJam. – maxb Sep 12 '18 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 '18 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 '18 at 9:32
• @KevinCruijssen: Thanks! Not sure how I missed that :P – Emigna Sep 12 '18 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, 9795929083 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, 929085 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 '18 at 13:09
• @JoKing Thanks, didn't know that I could return instead of printing when wrote it. – TFeld Sep 12 '18 at 13:14
• 82 bytes: len(w)<3 -> 'N'in w, 81 bytes : len(w)%2 -> (w<'N') – ovs Sep 12 '18 at 13:22

# Canvas, 27 bytes

｛╷⌐３％‽YeahＰ｝２％‽ButＰ｝３％╷‽NoＰ


Try it here!

# 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.

args[0].toLong().times{print((it%3?'':'Yeah\n')+(it%2?'':'But\n')+(it%3==1?'No\n':''))}


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 '18 at 15:20
• @maxb Thanks! I've added one :) – archangel.mjj Sep 12 '18 at 15:29
• Nice first answer and also welcome to PPCG. – ElPedro Sep 12 '18 at 18:03

# Retina 0.8.2, 45 bytes

.+
$* 1$Yeah¶$But¶$11No¶
+11B
B
111

A1


Try it online! Explanation:

.+
$*  Convert the input to unary. 1$Yeah¶$But¶$11No¶


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.

+11B
B


Remove pairs of 1s before Bs.

111


Remove 1s in groups of three everywhere else.

A1


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 '18 at 12:51

# 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.

Explanation:

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

• ++i%3>1 will likely save you a byte – Olivier Grégoire Sep 12 '18 at 22:56
• @OlivierGrégoire Ah, of course. Thanks! – Kevin Cruijssen Sep 13 '18 at 7:40

# Powershell, 75747267 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,"YeahnBut","But","No","But","Yeah","ButnNo",$null,...)
# 4. remove $null elements from result array } # Output results @( 0,1,2,10 ) | % { &$f $_ "======" } # Advanced test @( ,(0,'') ,(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"
}


Output:

======
Yeah
But
======
Yeah
But
No
======
Yeah
But
No
But
Yeah
But
No
Yeah
But
No
But
Yeah
======
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:

$args|?{$_}|%{0..--$_|%{@('Yeah')[$_%3]
@('But')[$_%2] @{1='No'}[$_%3]}}

• Great answer! Would it be possible to add some output to the answer, since it doesn't include an online interpreter? – maxb Sep 12 '18 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 '18 at 14:10
• That hashtable usage is clever. I'm going to need to remember that. – AdmBorkBork Sep 12 '18 at 18:35
• – TessellatingHeckler Sep 17 '18 at 5:07
• @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 '18 at 5:49 # Haskell, 71 bytes f n=[1..n]>>=(3?1)"Yeah"<>(2?1)"But"<>(3?2)"No" (a?b)c n=[c|nmoda==b]  Try it online! ### Explanation 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), 105999496 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! • Removing the interpolation like this saves 7 bytes. – Emigna Sep 12 '18 at 10:43 • @Emigna Thanks for the tip, changed the answer – auhmaan Sep 12 '18 at 16:33 • 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 '18 at 7:41 # Pip, 3735 33 bytes "But Yeah No "<>5@:^[t2io02x]@<a  (Note the space after But.) Takes input as a command-line argument. Try it online! ### Explanation This explanation is for the previous version--see below for changelog Inspired by Jo King's Perl 6 answer. We construct this list: [ "Yeah But "; "No "; "But "; "Yeah "; "But No "; "" ]  and output the first a elements of it using cyclic indexing. [t2io02x]R,3["But""Yeah""No"].n@<:a 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 replace: ,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 Flat##{Mask[_%3'2'3=0'0'1,$Yeah'$But'$No]}=>Iota


Try it online!

## Explanation

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), 77717472 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)

i;f(n){i=n&&n-i>=~n/6&&f(n,i++,puts(i%7%4?i%7%2?"But":"No":"Yeah"));}


Try it online!

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

# Ruby, 69 7274 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!

• 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 '18 at 2:21

## R, 65 bytes

cat(c("yeah","but","no")[c(3,1:3,2,1,2)][1:scan()%%7+1],sep="\n")


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

/^0/!s:$:g: :l;y:abcdefg:bcdefga: /[ae]/iYeah /[bdf]/iBut /[cg]/iNo s:.$:-&:;:s;s:0-:-9:;ts;h
y:123456789:012345678:;G
s:.*(.)-.*\n(.*).-:\2\1:;tl;c\


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.

### Explanation

/^0/!                            | if the input number doesnt 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 theres an 'a' or 'e' in the input… iYeah | …output 'Yeah' | /[bdf]/ | if theres a 'b' or 'd' or 'f' in the input… iBut | …output 'But' | /[cg]/ | if theres 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 '18 at 8:30
• @user285259 Done. – hidefromkgb Sep 21 '18 at 13:21

# Clean, 116 bytes

import StdEnv,Data.List
r=cycle
$n=[e\\_<-[1..n]&a<-r["Yeah","",""]&b<-r["But",""]&c<-r["","No",""],e<-[a,b,c]|e>""]  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. • I get some kind of build error for the TIO link, perhaps a syntax error in the testing code? – maxb Sep 13 '18 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 '18 at 8:36 • Shave 2 bytes with i=1 to p (and adjusting moduli, naturally). Reverse ranges are empty. :) – user82031 Sep 13 '18 at 18:16 • Nice! I've added that. Thanks! :) – Ciaran_McCarthy Sep 13 '18 at 20:56 # PHP, 65 68 bytes while($i<$argn)echo["Yeah "][$i%3],["But
"][$i%2],["No "][~-$i++%3];


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 '18 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 '18 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

Ungolfed

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
Next

• @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 '18 at 13:20
• 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 - reinstate Monica Sep 14 '18 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 '18 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 - reinstate Monica Sep 14 '18 at 13:30
• VBA will automatically concatenate function outputs, so you can drop the & between eachIIf(..) for an extra 2 bytes – Chronocidal Sep 14 '18 at 15:40

# Jelly, 22 bytes

5Rż7FṚṁị“'⁴\ÆẓNƇ»ḲŒP¤Ẏ


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)

### How?

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"]
["No"]
["But"]
["Yeah"]
["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"]
["No"]
["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]
“'⁴\Æẓ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 '18 at 5:01

# Python 2, 9392 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 '18 at 10:34
• @JonathanFrech - very cool! Similar technique can be applied to the other cases as well. Many thanks! – ElPedro Sep 17 '18 at 8:10