# 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 {
}
<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? – Zereges Nov 9 '15 at 18:15
• @Zereges In that matter, I am sorry. :( – Cows quack Nov 9 '15 at 19:30
• Maybe it should be called "Fizzo Nacci" – LegionMammal978 Nov 9 '15 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. – Chris Jester-Young Nov 12 '15 at 17:43
• @ChrisJester-Young it's still an unnecessarry limitation, that might make creative implementators steer clear of this task. And most of the solutions (including the 2nd most upvoted one) are breaking already – SztupY Nov 12 '15 at 19:24

## 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 ;? – Leif Willerts Nov 18 '15 at 21:47
• Oups, missed that one byte @LeifWillerts :). – HaskellElephant Dec 7 '15 at 11:26
• Well, seems like that "inspired" to improve much more :) – Leif Willerts Dec 7 '15 at 19:36
• What does d do? – Cyoce Aug 24 '16 at 23:43

# ><>, 78 bytes

01:n0\oo~o'F0ibo'\
aa:+1<}[3rn?/!?%3\!?%2:::::+}:}oa;?=*
ooooo'Nacci'/
00$0o\. Try it online! # 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 – Erik the Outgolfer Jun 18 '16 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";
}

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