| Bytes | Lang | Time | Link |
|---|---|---|---|
| 076 | powershell | 240523T195107Z | groser |
| 103 | Kotlin | 200610T144316Z | Lamorak |
| 117 | Java OpenJDK 8 | 200610T034159Z | branboye |
| 098 | C gcc | 200608T202702Z | Noodle9 |
| 047 | Brachylog | 200609T110306Z | Unrelate |
| 079 | Python 2 | 200609T045917Z | Dion |
| 043 | APL Dyalog Unicode | 200609T061150Z | Bubbler |
| 076 | Python 3 | 200608T184649Z | Surculos |
| 033 | 05AB1E | 200608T155902Z | Kevin Cr |
| 039 | Charcoal | 200608T183853Z | Neil |
| 063 | Bash | 200608T180903Z | Mitchell |
| 056 | Retina 0.8.2 | 200608T173154Z | Neil |
| 026 | Jelly | 200608T165734Z | Jonathan |
| 064 | JavaScript ES6 | 200608T161122Z | Arnauld |
| 047 | perl M5.010 n | 200608T160944Z | Abigail |
powershell, 76 bytes
[regex]::Match("pwsh`nfizz`nbuzz`n'ave a banana","(?s)(?<=$($_)\n).*$")|% v*
Kotlin, 103 bytes
fun f(x:String){listOf("fizz","buzz","'ave a banana").fold("Kotlin"){a,b->if(x==a){println(b);f(b)};b}}
Java (OpenJDK 8), 117 bytes
void a(String s){System.out.println(s=s=="fizz"?"buzz":s=="buzz"?"'ave a banana":s=="java"?"fizz":"");if(s!="")a(s);}
C (gcc), 115 \$\cdots\$ 105 98 bytes
Saved 4 bytes thanks to ceilingcat!!!
Saved 7 bytes thanks to Neil!!!
i;*y[]={"c","fizz","buzz","'ave a banana"};f(char*s){for(i=0;i<3;)strcmp(s,y[i++])||puts(s=y[i]);}
Brachylog, 52 47 bytes
∧"Brachylog
fizz
buzz
'ave a banana"ṇ;?⟨a₁h⟩b~ṇ
The predicate fails on inputs on which it should "terminate". If outputting an unbound variable is more desirable, +2 bytes for .∨; if an empty string is necessary, +1 on top of that for Ẹ.
Python 2, 102 79 bytes
a='fizz'
b='buzz'
def f(s):t={'Python':a,a:b,b:"'ave a banana"}[s];print t;f(t)
Uses a different approach from the other answer, recursive function
Edit: Thanks @SurculoseSputum for saving 23 bytes!
APL (Dyalog Unicode), 43 bytes
'APL' 'fizz' 'buzz' '''ave a banana'(↑⍳↓⊣)⊂
List of string literals is quite expensive...
How it works
S←'APL' 'fizz' 'buzz' '''ave a banana' ⍝ Let's call this array S
S(↑⍳↓⊣)⊂ ⍝ The function
S( ⍳ )⊂ ⍝ 1-based index of the input in S, 5 if not found
↓⊣ ⍝ Drop that many items from the start of S
↑ ⍝ Convert the remaining items to be placed on each line
Python 3, 77 76 bytes
t="Python","fizz","buzz","'ave a banana"
*map(print,t[t.index(input())+1:]),
Takes input from STDIN, and print the results to STDOUT.
05AB1E, 46 33 bytes
’
05AB1E
fizz
ÒÖ
'ž™ a æé’I¶.ø¡¦θ
-13 bytes by porting @Abigail's Perl answer, so make sure to upvote her!!
Outputs [] for invalid inputs.
Original 46 bytes approach:
"fizz"U•äƵí•hRQiX=}XQi'ÒÖ=}'ÒÖQi’'ž™ a æé’,}õ?
Outputs nothing for invalid inputs.
Explanation:
’
05AB1E
fizz
ÒÖ
'ž™ a æé’ '# Push dictionary string "\n05AB1E\nfizz\nbuzz\n'ave a banana"
I # Push the input
¶.ø # Surround it with leading and trailing newline
¡ # Split the string on this
¦ # Remove the first part (for invalid inputs)
θ # Pop and only leave the last part (or an empty list)
# (and output it implicitly as result)
"fizz"U # Puts "fizz" in variable `X`
•äƵí• # Push compressed integer 14793296
h # Convert it to hexadecimal: E1BA50
R # Reverse it to 05AB1E
Qi } # If the (implicit) input-string is equal to this:
X # Push "fizz" from variable `X`
= # Print it with trailing newline without popping
X # Push "fizz" from variable `X`
Qi } # If the top of the stack equals "fizz",
# which will use the (implicit) input if the stack is empty:
'ÒÖ '# Push dictionary string "buzz"
= # Print it with trailing newline without popping
'ÒÖQi } '# If the top of the stack (or implicit input) equals "buzz":
’'ž™ a æé’ '# Push dictionary string "'ave a banana"
, # Pop and print it
õ? # Print "" without newline
# (for invalid input, which otherwise would be output implicitly)
See this 05AB1E tip of mine (sections How to use the dictionary? and How to compress large integers?) to understand why •äƵí• is 14793296; 'ÒÖ is "buzz"; and ’'ž™ a æé’ is "'ave a banana".
Charcoal, 39 bytes
≔⪪“Jε(h&]⦄_⁷¦⊗‹f·ⅈ⦄⊗x⍘ς3➙A⁸“↑”¶υΦυ№…υκθ
Try it online! Link is to verbose version of code. Explanation:
≔⪪“Jε(h&]⦄_⁷¦⊗‹f·ⅈ⦄⊗x⍘ς3➙A⁸“↑”¶υ
Split the string Charcoal\nfizz\nbuzz\n'ave a banana on newlines and save the result in a variable.
Φυ№…υκθ
Filter on the result and show only those entries that appear after the input.
Bash, 63 bytes
bash=fizz
fizz=buzz
buzz="'ave a banana"
echo ${x=${!1}}&&$0 $x
This requires . to be in your PATH. If that's not acceptable, then replace $0 with ./$0 (assuming the program is being run from the current working directory) at the cost of 2 bytes (65 bytes total).
Input is passed as an argument, output is on stdout. The language name is entered as bash.
(There's spurious output to stderr, but that's OK under our generic rules.)
Retina 0.8.2, 56 bytes
$
¶Retina¶fizz¶buzz¶'ave a banana
^(.*¶)(.*¶)*?(\1|.*$)
Try it online! Link includes test cases. Explanation:
$
¶Retina¶fizz¶buzz¶'ave a banana
Append the possible inputs and outputs.
^(.*¶)(.*¶)*?(\1|.*$)
Try to delete only up to and including a line matching the original input. If this is not possible, then just delete everything.
Jelly, 26 bytes
“Çȥȧ>$ỌĿɦ@⁴Ƙ½Æ/ṠṫḞƇ»Ỵṣ⁸ḊẎY
How?
“...»Ỵṣ⁸ḊẎY - Link: list of characters, W
“...» - compressed string = "Jelly\nfizz\nbuzz\n'ave a banana"
Ỵ - split at newlines = ["Jelly","fizz","buzz","'ave a banana"]
ṣ - split at:
⁸ - chain's left argument, W e.g. "Jelly" -> [[],["fizz","buzz","'ave a banana"]]
Ḋ - dequeue = [["fizz","buzz","'ave a banana"]]
Ẏ - tighten = ["fizz","buzz","'ave a banana"]
Y - join with new lines = "fizz\nbuzz\n'ave a banana"
JavaScript (ES6), 64 bytes
Expects "js" for the language name. Returns an array of strings.
s=>[k="js","fizz","buzz","'ave a banana"].filter(w=>k*(k|=s==w))
perl -M5.010 -n, 47 bytes
"Perl\nfizz\nbuzz\n'ave a banana"=~/\b$_/;say$'
Prints whatever is following the input, or nothing if there is no match. Assumes input is newline terminated.