# Fibonacci + Fizz Buzz = Fibo Nacci!

Fibonacci + FizzBuzz = Fibo Nacci!

# Your challenge is to create a Fibo Nacci program!

• A Fibo Nacci program outputs the first 100 Fibonacci numbers (starting from 1).
• If the Fibonacci number is divisible by both 2 and 3 (i.e. it is divisible by 6), then output FiboNacci instead of the number.
• Otherwise, if the Fibonacci number is divisible by 2, then output Fibo instead of the number.
• Otherwise, if the Fibonacci number is divisible by 3, then output Nacci instead of the number.

# Rules

• The program should take no input.
• The program should output a new line (\n) after every entry.
• The program should not print anything to STDERR.
• The program must output the first 100 Fibo Nacci entries (starting from 1).
• Standard loopholes are not allowed (by default).
• This is so shortest code in bytes wins!

Here is the expected output:

1
1
Fibo
Nacci
5
Fibo
13
Nacci
Fibo
55
89
FiboNacci
233
377
Fibo
Nacci
1597
Fibo
4181
Nacci
Fibo
17711
28657
FiboNacci
75025
121393
Fibo
Nacci
514229
Fibo
1346269
Nacci
Fibo
5702887
9227465
FiboNacci
24157817
39088169
Fibo
Nacci
165580141
Fibo
433494437
Nacci
Fibo
1836311903
2971215073
FiboNacci
7778742049
12586269025
Fibo
Nacci
53316291173
Fibo
139583862445
Nacci
Fibo
591286729879
956722026041
FiboNacci
2504730781961
4052739537881
Fibo
Nacci
17167680177565
Fibo
44945570212853
Nacci
Fibo
190392490709135
308061521170129
FiboNacci
806515533049393
1304969544928657
Fibo
Nacci
5527939700884757
Fibo
14472334024676221
Nacci
Fibo
61305790721611591
99194853094755497
FiboNacci
259695496911122585
420196140727489673
Fibo
Nacci
1779979416004714189
Fibo
4660046610375530309
Nacci
Fibo
19740274219868223167
31940434634990099905
FiboNacci
83621143489848422977
135301852344706746049
Fibo
Nacci


## The Catalogue

The Snack Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

## Language Name, N bytes


where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes


If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes


You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes


/* Configuration */

var QUESTION_ID = 63442; // Obtain this from the url
// It will be like http://XYZ.stackexchange.com/questions/QUESTION_ID/... on any question page
var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk";
var OVERRIDE_USER = 41805; // This should be the user ID of the challenge author.

/* App */

return "http://api.stackexchange.com/2.2/questions/" +  QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER;
}

}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(a) {
});
comment_page = 1;
}
});
}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(c) {
if (c.owner.user_id === OVERRIDE_USER)
});
else process();
}
});
}

var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/;

function getAuthorName(a) {
return a.owner.display_name;
}

function process() {
var valid = [];

var body = a.body;
if(OVERRIDE_REG.test(c.body))
body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>';
});

var match = body.match(SCORE_REG);
if (match)
valid.push({
user: getAuthorName(a),
size: +match[2],
language: match[1],
});
else console.log(body);
});

valid.sort(function (a, b) {
var aB = a.size,
bB = b.size;
return aB - bB
});

var languages = {};
var place = 1;
var lastSize = null;
var lastPlace = 1;
valid.forEach(function (a) {
if (a.size != lastSize)
lastPlace = place;
lastSize = a.size;
++place;

.replace("{{NAME}}", a.user)
.replace("{{LANGUAGE}}", a.language)
.replace("{{SIZE}}", a.size)

var lang = a.language;
lang = jQuery('<a>'+lang+'</a>').text();

languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang, user: a.user, size: a.size, link: a.link};
});

var langs = [];
for (var lang in languages)
if (languages.hasOwnProperty(lang))
langs.push(languages[lang]);

langs.sort(function (a, b) {
if (a.lang_raw.toLowerCase() > b.lang_raw.toLowerCase()) return 1;
if (a.lang_raw.toLowerCase() < b.lang_raw.toLowerCase()) return -1;
return 0;
});

for (var i = 0; i < langs.length; ++i)
{
var language = jQuery("#language-template").html();
var lang = langs[i];
language = language.replace("{{LANGUAGE}}", lang.lang)
.replace("{{NAME}}", lang.user)
.replace("{{SIZE}}", lang.size)
language = jQuery(language);
jQuery("#languages").append(language);
}

}
body { text-align: left !important}

width: 290px;
float: left;
}

#language-list {
width: 290px;
float: left;
}

font-weight: bold;
}

table td {
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="language-list">
<h2>Shortest Solution by Language</h2>
<table class="language-list">
<tr><td>Language</td><td>User</td><td>Score</td></tr>
<tbody id="languages">

</tbody>
</table>
</div>
<tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr>

</tbody>
</table>
</div>
<table style="display: none">
</tbody>
</table>
<table style="display: none">
<tbody id="language-template">
</tbody>
</table>

• What about languages with highest integer type of only 64 bits? :( Isn't 90 fib. numbers enough? Nov 9, 2015 at 18:15
• @Zereges In that matter, I am sorry. :( Nov 9, 2015 at 19:30
• Maybe it should be called "Fizzo Nacci" Nov 9, 2015 at 22:56
• @SztupY Because the output in this question is completely invariant, you don't even need integers at all. Just treat this question as a kolmogorov-complexity question (I even added the tag) and go from there. Nov 12, 2015 at 17:43
• Math comment: every third Fibonacci number is even, and every fourth Fibonacci number is a multiple of 3. This might lead to alternate coding strategies, which don't require testing divisibility. Aug 24, 2016 at 18:14

## Javascript (ES6), 117 108 bytes

let s=[1,1],i;for(i=1;i<101;s[++i]=s[i-1]+s[i-2]);s.map(n=>console.log((n%2?"":"Fibo")+(n%3?"":"Nacci")||n))


Try it online here.

Sadly this breaks after the 77th number, because Javascript doesn't support numbers that high. I think this is still cool enough to warrant an answer, though.

It generates the entire range of numbers, then iterates with map to print out the appropriate string.

Takes advantage of the fact that console.log prints on a new line. Could also use alert, but that's more annoying.

main=putStr.unlines.take 100$0!1 x!y=d 3"Nacci"(d 2"Fibo"id)(show y):y!(x+y) where d z a f b|mod y z>0=f b|1>0=f""++a  ungolfed:  main = putStr . unlines . take 100$ f 0 1
f x y
= d 3 "Nacci" (d 2 "Fibo" id) (show y) : f y (x+y)
where
d z a g b
| mod y z > 0 = g b
| otherwise   = g "" ++ a

• Why ;  instead of ;? Nov 18, 2015 at 21:47
• Oups, missed that one byte @LeifWillerts :). Dec 7, 2015 at 11:26
• Well, seems like that "inspired" to improve much more :) Dec 7, 2015 at 19:36
• What does d do? Aug 24, 2016 at 23:43

# ><>, 78 bytes

01:n0\oo~o'F0ibo'\
aa:+1<}[3rn?/!?%3\!?%2:::::+}:}oa;?=*
ooooo'Nacci'/
00$0o\.  Try it online! ## Python 3, 10094 88 bytes a,b=0,1 exec("print(f\"{''if b%2else'Fibo'}{''if b%3else'Nacci'}\"or b);a,b=b,a+b;"*100)  Try it online! # JavaScript, 82 78 bytes -4 bytes thanks to xigio for(n=a=b=1;n++n<102;b=a+(a=b))alert((a%2n?'':'Fibo')+(a%3n?'':'Nacci')||a+'')  Uses JavaScript's BigInt (not supported in IE) to get to get all the way up to 100. • 78 bytes: for(n=a=b=1n;++n<102;b=a+(a=b))alert((a%2n?'':'Fibo')+(a%3n?'':'Nacci')||a+'') Jan 25, 2022 at 10:25 • @xigoi Duh, I should've seen that... I had all the parts right there Jan 25, 2022 at 21:29 # Javascript ES6 112 bytes var f=(a,b,c)=>{if(!(99<c)){var d=a%2?"":"Fibo",e=a%3?"":"Nacci";console.log(d||e?d+e:n);f(b,a+b,c+1)}};f(1,1,0)  As with other JS answers, fails after 73rd number because of js use of floats • Why var? You can save 8 bytes omitting it, making globals instead. There is no consensus saying that functions can't create globals. Also, you can omit f=, making an anonymous function, saving another -2 bytes. Final save: -10 bytes Final size: 102 bytes Jun 18, 2016 at 21:59 ## Perl, 146 Bytes use bigint;$a=$b=1;for$i(0..99){$l=($a%2==0?2:0)+($a%3==0?1:0);print$a if$l==0;print"Fibo"if$l&2;print"Nacci"if$l&1;print"\n";($a,$b)=($b,$a+$b);}


Uncompressed:

#!/usr/bin/perl
use bigint;
$a=$b=1;
for$i(0..99) {$l=($a%2==0?2:0)+($a%3==0?1:0);
print $a if$l == 0;
print "Fibo" if $l & 2; print "Nacci" if$l & 1;
print "\n";
($a,$b)=($b,$a+$b); }  old version with 156 bytes... use bigint;$a=$b=1;for$i(0..99){if($a%2==0){print"Fibo";print($a%3==0?"Nacci\n":"\n");}elsif($a%3==0){print"Nacci\n";}else{print"$a\n";}($a,$b)=($b,$a+$b);}  Uncompressed: #!/usr/bin/perl use bigint;$a=$b=1; for$i (0..99) {
if($a%2 == 0) { print "Fibo"; print ($a%3 == 0 ? "Nacci\n" : "\n");
} elsif($a%3 == 0) { print "Nacci\n"; } else { print "$a\n";
}
($a,$b)=($b,$a+$b); }  ## Javascript (ES2015), 99 bytes f=n=>n<3?1:f(n-1)+f(n-2);for(i=0;i<100;)console.log((f(++i)%2?'':'Fibo')+(f(i)%3?'':'Nacci')||f(i))  Ungolfed: // fibonacci function var fibonacci = (n) => n < 3 ? 1 : fibonacci(n-1) + fibonacci(n-2) // (implicit return) for (var i = 0; i<100;) { var output = fibonacci(++i) % 2 !== 0 ? '' : 'Fibo'; output += fibonacci(i) % 3 !== 0 ? '' : 'Nacci'; console.log(output || fibonacci(i)); }  • Use alert instead of console.log; it shaves off some bytes. Nov 13, 2015 at 6:28 # C, 121 bytes Had to go full __int128_t for this to work. printf doesn't know how to handle a 128bit integer, so the last four numeric values will be printed wrong. Still, it was fun to code, so here you go: __int128_t a,b=1,c;i=100;main(){while(i--){c=b;b%=6;printf(b?b%2?b-3?"%lu\n":"Nacci\n":"Fibo\n":"FiboNacci\n",c);b=c+a;a=c;}}  compiled with gcc-4.8 fibo.c on x86_64. • while is always longer than or as long as for. Feb 12, 2018 at 21:51 # Prolog, 182 bytes f(A,B,X):-X<100,C is A+B,Z is X+1,(Y is B mod 6,Y=0->writeln('FiboNacci');(Y is B mod 2,Y=0->writeln('Fibo');(Y is B mod 3,Y=0->writeln('Nacci');writeln(B)))),f(B,C,Z). p:-f(0,1,0).  Try it out online here To run the program, use the query: p.  Python 3, 137 bytes Fun question with lots of new things I learnt in doing it. Python3 isn't a golfing language, but I suppose this isn't too bad f=lambda n:n if n<2 else f(n-2)+f(n-1) for n in range(100):t=f(-~n);x="Fibo"*(t%2==0)+"Nacci"*(t%3==0);print(x if t%2==0 or t%3==0 else t)  Hardest part was just to get it to only print the number First line calculates the nth fib number. Second line joins Fibo and Nacci if it fits the rules an then it prints that string if it should else print the nth fib number. • 2else instead of 2 else for -1 byte, n+1 instead of -~n because -~n is unneeded, t%2<1 instead of t%2==0 for -1 byte, t%3<1 instead of t%3==0 for -1 byte, t%2<1or t%3<1else instead of t%2==0 or t%3==0 else for -4 bytes. Total save: -7 bytes. Jun 18, 2016 at 21:48 # ///, 642 bytes /A/ Fibo//B/ Nacci//*/ANacci //^/AB /1 1^5A 13BA 55 89*233 377^1597A 4181BA 17711 28657*75025 121393^514229A 1346269BA 5702887 9227465*24157817 39088169^165580141A 433494437BA 1836311903 2971215073*7778742049 12586269025^53316291173A 139583862445BA 591286729879 956722026041*2504730781961 4052739537881^17167680177565A 44945570212853BA 190392490709135 308061521170129*806515533049393 1304969544928657^5527939700884757A 14472334024676221BA 61305790721611591 99194853094755497*259695496911122585 420196140727489673^1779979416004714189A 4660046610375530309BA 19740274219868223167 31940434634990099905*83621143489848422977 135301852344706746049AB  # F#, 153 134 bytes let rec L c n p=printfn"%s"(c%6m|>function|0m->"FiboNacci"|2m|4m->"Fibo"|3m->"Nacci"|_->string c);if n<100 then L(p+c)(n+1)c L 1I 1 0I  Edit: Used decimal instead of bigint which allowed using pattern matching. Stole the internal logic from the other F# answer. My older filtering logic is in the below snippets. One liner, same logic, 155 bytes: let rec L c n p=printfn"%s"(if c%6I=0I then"FiboNacci"elif c%2I=0I then"Fibo"elif c%3I=0I then"Nacci"else string c);if n<100 then L(p+c)(n+1)c in L 1I 1 0I  Different logic, 168 bytes: Seq.unfold(fun(p,c)->Some((if c%6I=0I then"FiboNacci"elif c%2I=0I then"Fibo"elif c%3I=0I then"Nacci"else string c),(c,c+p)))(0I,1I)|>Seq.take 100|>Seq.iter(printfn"%s")  ## Perl6, 59 58 say "Fibo"x$_%%2~"Nacci"x$_%%3||$_ for (1,1,*+*...*)[^100]


## Javascript, 157 155 bytes

Golfed:

function g(n){a=!n%2;b=!n%3;a&&b?return "FiboNacci":;b?return "Nacci";a?return "Fibo";return n==1||n==2?1:f(n-1)+f(n-2)}for(n=100;n++>0;)console.log(f(n))


Ungolfed:

function fibonacci(n){
if(n==1||n==2) return 1;
return(fibonacci(n-1)+fibonacci(n-2));
}
function fibonacci2(n){
a=!(n%2);
b=!(n%3);
if(a&&b) return "FiboNacci";
if(a) return "Fibo";
if(b) return "Nacci";
return fibonacci(n);
}
for(n=100;n++>0;) console.log(fibonacci2(n));


Saved 3 bytes thanks to Cows Quack's comment

• Thanks! By the way, why is there a minimum comment length? Nov 12, 2015 at 21:02
• There is a minimum comment length to prevent comments like "Good Job!" or "+1" and stuff like that. Nov 13, 2015 at 6:26
• @ΚριτικσιΛίθος Why is there also a minimum amount of reputation to be able to post comments then? Nov 15, 2015 at 23:32
• Change your for-loop to for(n=100;n++>0;)console.log(f(n)) It saves 3 bytes Nov 16, 2015 at 14:24
• @ΚριτικσιΛίθος OK, thanks. Editing post. Nov 16, 2015 at 22:16

# Swift 5.9, 129 bytes

let f={$0<3 ?1:f($0-UInt64(1))+f(\$0-2)},m="Fibo",n="Nacci"
for i in 1...30{print(i%12<1 ?m+n:i%3<1 ?m:i%4<1 ?n:"\(f(.init(i)))")}