46
10
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
3Can we return a list of lines? – Jo King – 2018-09-12T08:20:33.263
1@JoKing if your language allows it. I'm not 100% sure on the rules, but I think it's permissible to have a function return a list of lines in Python, which can then be joined in the footer. – maxb – 2018-09-12T08:31:30.127
10It 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 – 2018-09-12T09:54:47.3871@Arnauld I contemplated renaming the variable before posting the challenge, but I wanted to stay true to the source. – maxb – 2018-09-12T10:00:47.253
10Do we get a bonus if the last line is "God can't believe you just said that!" – Ciaran_McCarthy – 2018-09-12T10:24:47.427
1Shouldn't the output be "Yeah / No / But / Yeah / But / Yeah..."? – Erik the Outgolfer – 2018-09-12T15:33:21.547
3@EriktheOutgolfer the
if
s fall trough and continue in the current loop if their condition was satisfied. – dzaima – 2018-09-12T15:35:20.7334The most Australian codegolf yet? Except it should be "nah" – Nacht - Reinstate Monica – 2018-09-13T02:00:12.293
3
@Nacht This is surely a Little Britain reference, no? That was my assumption, anyway.
– JBentley – 2018-09-14T00:32:11.5232Has anyone noticed yet that this script is not only hideously verbose but also incorrect? The actual number of buts is only half of the demanded
nrOfButs
! (except for input1
) – Titus – 2018-09-14T06:35:14.7401We must not handle faulty input? So I disqualify if I do? – Ingo Bürk – 2018-09-14T12:53:41.103
@IngoBürk Darn it, you got me. Now I'll have to disqualify you – maxb – 2018-09-14T13:13:36.623
In the input=10 example, there is a "No" immediately followed by a "Yeah". Is that intended? – JDL – 2018-09-14T14:07:50.570
@JDL yes and no. My colleague wrote the code in a slack post, probably without ever running it himself. I chose to keep the code as is, which makes it "intended", I guess. – maxb – 2018-09-14T14:11:46.453
okay --- so we are reproducing specifically that code, not the first n words of "yeah but no but" repeated ad infinitum. – JDL – 2018-09-14T14:13:24.180
1@JDL Exactly! I've had quite a few answers that didn't look at the code above, but instead just printed
n
lines of "Yeah But No". Those are not valid answers, as the challenge is to accurately imitate the code above. – maxb – 2018-09-14T14:14:55.867@maxb One more serious note: "And since it is common knowledge that a shorter program is faster to write..." Here it is common knowledge that in code golfing, a shorter program is slower to write. – trolley813 – 2018-09-17T09:56:22.687
@trolley813 it should be faster to write, since the only limiting factor is the number of keystrokes. No I understand your point, I was just being sarcastic. – maxb – 2018-09-17T10:16:06.217