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

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

## 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 ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe";
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;
}

function commentUrl(index, answers) {
return "http://api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER;
}

jQuery.ajax({
method: "get",
dataType: "jsonp",
crossDomain: true,
success: function (data) {
data.items.forEach(function(a) {
var id = +a.share_link.match(/\d+/);
});
if (!data.has_more) more_answers = false;
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>)/;

var OVERRIDE_REG = /^Override\s*header:\s*/i;

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>
<link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">
<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. :( – Kritixi Lithos 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

# Pyth, 37 bytes

I loop through the Fibonacci numbers instead of generating them beforehand, since it's really short to do.

K1V100|+*"Fibo"!%=+Z~KZ2*"Nacci"!%Z3Z


Try it online.

• Congratulations for winning this challenge! I liked that this solution was fast. – Kritixi Lithos Nov 15 '15 at 19:45

## Python 2, 62 bytes

a=b=1;exec"print~a%2*'Fibo'+~a%3/2*'Nacci'or a;a,b=b,a+b;"*100


Not much different from the standard FizzBuzz, really.

• This is amazing. – J Atkin Nov 10 '15 at 18:15
• I need to remember this looping construct for my next Ruby golf. This is amazing. – clap Nov 16 '15 at 16:28

# C++11 metaprogramming, 348 bytes

#include<iostream>
#define D static const unsigned long long v=
template<int L>struct F{D F<L-1>::v+F<L-2>::v;};template<>struct F<2>{D 1;};template<>struct F<1>{D 1;};template<int Z>struct S:S<Z-1>{S(){auto&s=std::cout;auto l=F<Z>::v;s<<(l%2?"":"Fibo")<<(l%3?"":"Nacci");(l%2&&l%3?s<<l:s)<<"\n";}};template<>struct S<0>{S(){}};int main(){S<100>s;}


Because, why not. It compiles with warning C4307: '+': integral constant overflow, runs fine, but 93+ th Fibonacci numbers are not shown correctly (due to overflow), so this is invalid entry (but I could not win it with that much of bytes though)

Ungolfed

#include <iostream>
#define D static const unsigned long long v =
template<int L>struct F { D F<L - 1>::v + F<L - 2>::v; };
template<>struct F<2> { D 1; };
template<>struct F<1> { D 1; };

template<int Z>struct S : S<Z - 1>
{
S()
{
auto&s = std::cout;
auto l = F<Z>::v;
s << (l % 2 ? "" : "Fibo")
<< (l % 3 ? "" : "Nacci");
(l % 2 && l % 3 ? s << l : s) << "\n";
}
};

template<>struct S<0>
{
S() { }
};

int main()
{
S<100>s;
}

• You could use exploded strings (template <char H, char ...T>) in your templates to (theoretically) handle arbitrary-length values. Then it would just be a matter of examining the last 2 characters in each string to determine divisibility by 2 and/or 3. – Mego Nov 9 '15 at 20:23
• @Mego I do not understand you. How it would help me to handle values, which do not fit into 64 bits. Also, You need all digits to find out if the number is divisible by 3. – Zereges Nov 9 '15 at 21:12
• Strings can be arbitrarily long (until you run out of memory). And you're right, I messed up my comment. Still, you could compute the digital sum to determine divisibility by 3. – Mego Nov 9 '15 at 21:27
• @Mego Implementing addition of those strings would require much more effort. – Zereges Nov 9 '15 at 22:17
• You could use the gnu dialect and use __uint128_t, maybe. – user16488 Nov 12 '15 at 21:54

## C#, 175 171 152 145 bytes

class c{static void Main(){for(dynamic a=1m,b=a,c=0;c++<100;b=a+(a=b))System.Console.WriteLine(a%6>0?a%2>0?a%3>0?a:"Nacci":"Fibo":"FiboNacci");}}


Uncompressed:

class c {
static void Main()
{
for (dynamic a = 1m, b = a, c = 0; c++ < 100; b = a + (a = b))
System.Console.WriteLine(a%6>0?a%2>0?a%3>0?a:"Nacci":"Fibo":"FiboNacci");
}
}

• Even compressing the output with a DeflateStream the lowest I could get was 191 chars so this is likely very close to the best possible c# answer. A shame BigInteger is required. – Jodrell Nov 10 '15 at 10:28
• "using System;" will give another -1 in size. – olegz Nov 10 '15 at 17:18
• I still had to prefix System.Numerics with System despite the using :-S, so I'm not sure the using will work. – Jodrell Nov 10 '15 at 17:22
• You can save 3 characters by replacing the ==0s with >0 and inverting the ternaries: class c{static void Main(){for(System.Numerics.BigInteger a=1,b=1,c=0;c++<100;b=a+(a=b))System.Console.WriteLine(a%6>0?a%2>0?a%3>0?a:(object)"Nacci":"Fibo":"FiboNacci");}} – Bob Nov 11 '15 at 4:53
• You can save another 7 characters by changing decimal a=1,b=1 to dynamic a=1m,b=a and then you can lose the (object) :) – Timwi Nov 11 '15 at 21:58

## Oracle SQL, 212 bytes

Not a golfing language but I had to try...

Concatenating all the rows with \n:

WITH F(R,P,C)AS(SELECT 1,0,1 FROM DUAL UNION ALL SELECT R+1,C,P+C FROM F WHERE R<100)SELECT LISTAGG(NVL(DECODE(MOD(C,2),0,'Fibo')||DECODE(MOD(C,3),0,'Nacci'),''||C),CHR(13))WITHIN GROUP(ORDER BY R)||CHR(13)FROM F


SQLFIDDLE

Or with one entry from the sequence per row (162 bytes):

WITH F(R,P,C)AS(SELECT 1,0,1 FROM DUAL UNION ALL SELECT R+1,C,P+C FROM F WHERE R<100)SELECT NVL(DECODE(MOD(C,2),0,'Fibo')||DECODE(MOD(C,3),0,'Nacci'),''||C)FROM F

• Awesome, just for using SQL – Wayne Werner Nov 10 '15 at 14:23
• Just use the last one, since it is the "equivalent" to outputting "per line". And it really is a fine piece of code. Well done! – Ismael Miguel Nov 11 '15 at 9:20
• @IsmaelMiguel If it's run in SQL*Plus (or another command line interface) then there will be a newline output after each row (as part of how it reports the query output). However, that is a function of the CLI and not the SQL language - to be compliant with the rule The program should output a new line (\n) after every entry I'll leave it as the longer code but the shorter one could be made compliant (without relying on a CLI) by adding ||CHR(13) before the final FROM for 171 chracters. – MT0 Nov 11 '15 at 10:30
• Couldn't you use "\n"? Seems to work on MySQL. (Running select length("\n") returns 1, and running select "\n" doesn't return n, as with select "\p" returns p due to being an invalid escape) – Ismael Miguel Nov 11 '15 at 10:33
• SELECT LENGTH('\n') FROM DUAL outputs 2 in Oracle as '\n' does not get converted to CHR(13). – MT0 Nov 11 '15 at 10:43

# ShapeScript, 83 bytes

11'1?1?+'77*2**!""'"%r
"@+@0?2%1<"Fibo"*1?3%1<"Nacci"*+0?_0>"@"*!#%'52*0?**!"'"$""~  Try it online! • Literally looks like my cat jumped on top of my keyboard while I tried to turn on sticky keys. Nice job. – phase Nov 10 '15 at 5:38 • @phase figuratively. Either that or you're not looking too closely. Or you have a tiny cat or a giant keyboard. Because this cat managed to type Fibo and Nacci but otherwise avoid all letter keys save for one r. – John Dvorak Nov 10 '15 at 13:50 • @JanDvorak I think phase has macros setup for that ;) – Wayne Werner Nov 10 '15 at 14:22 • @phase 1. Why is your cat in your room?; 2. why would you want to turn on sticky keys? 3? Why do you not have a cat trap box on your desk to avoid your cat jumping on your keyboard? – Nzall Nov 11 '15 at 23:55 # Java, 407398351 308 bytes Golfed it with help from @Geobits and @SamYonnou Spread the word: Verbose == Java import java.math.*;class A{public static void main(String[]w){BigInteger a=BigInteger.ZERO,b=a.flipBit(0),c,z=a,t=a.flipBit(1),h=t.flipBit(0),s=t.flipBit(2);for(int i=0;i<100;i++){System.out.println(b.mod(s).equals(z)?"FiboNacci":b.mod(t).equals(z)?"Fibo":b.mod(h).equals(z)?"Nacci":b);c=a;a=b;b=c.add(b);}}}  Ungolfed version: import java.math.*; class A { public static void main(String[]w) { BigInteger a=BigInteger.ZERO,b=a.flipBit(0),c,z=a,t=a.flipBit(1),h=t.flipBit(0),s=t.flipBit‌​(2); for(int i=1;i<=100;i++) { System.out.println(b.mod(s).equals(z)?"FiboNacci":b.mod(t).equals‌​(z)?"Fibo":b.mod(h).equals(z)?"Nacci":b); c=a;a=b;b=c.add(b); } } }  • This can be golfed more. Import java.math.* instead of the whole thing. Use the constants for ONE and ZERO instead of new BigIntegers. Remove the public from the class. Pack everything except the println statement in the for body inside the loop declaration, etc. I recommend looking over the Java golfing tips in general. – Geobits Nov 10 '15 at 16:50 • @Geobits Done! 'Twas a pity that I was unfamiliar with BigInteger and its various golfing techniques. – Sock Nov 10 '15 at 17:05 • Storing BigInteger.ZERO, using flipBit(...) as an alternative to new BigInteger(...), and some other minor things you can get it down to 308: import java.math.*;class A{public static void main(String[]w){BigInteger a=BigInteger.ZERO,b=a.flipBit(0),c,z=a,t=a.flipBit(1),h=t.flipBit(0),s=t.flipBit(2);for(int i=0;i<100;i++){System.out.println(b.mod(s).equals(z)?"FiboNacci":b.mod(t).equals(z)?"Fibo":b.mod(h).equals(z)?"Nacci":b);c=a;a=b;b=c.add(b);}}} – SamYonnou Nov 10 '15 at 17:26 • Looks like BigInteger always returns BigInteger.ZERO when some operation like add(...) evaluates to zero so you can use == instead of .equals(z), also you can do away with storing s=t.flipBit‌​(2) (6) and instead do some clever inner assignment like so: import java.math.*;class A{public static void main(String[]w){BigInteger a=BigInteger.ZERO,b=a.flipBit(0),c,d,z=a,t=a.flipBit(1),h=t.flipBit(0);for(int i=0;i<100;i++){System.out.println((c=b.mod(t)).add(d=b.mod(h))==z?"FiboNacci":c==z?"Fibo":d==z?"Nacci":b);c=a;a=b;b=c.add(b);}}} these changes get it down to 280 – SamYonnou Nov 10 '15 at 18:00 • I think you mean Verbose.isEqualTo(Java) – Cyoce Aug 24 '16 at 22:46 ## Mathematica, 80 bytes a=b_/;#∣b&;Print/@(Fibonacci@Range@100/.{%@6->FiboNacci,%@2->Fibo,%@3->Nacci})  Adaptation of my older FizzBuzz solution. • @JacobAkkerboom Sorry, fixed. Also, for versions less than 10.3, replace Echo with Print. – LegionMammal978 Nov 24 '15 at 13:31 # Ruby, 71 66 bytes a=b=1;100.times{puts [b,f='Fibo',n='Nacci',f,b,f+n][~b%6];a=b+b=a}  ### ungolfed: a = b = 1 #starting values 100.times{ # create an array, and selects a value depending on the current number puts([b, 'Fibo', 'Nacci', 'Fibo', b, 'FiboNacci'][~b%6]) a=b+b=a # magic }  • I've worked on this for longer than I'd like to admin and can't find any way to improve it. f,n=%w[Fibo Nacci],f,n='Fibbo','Nacci' and f='Fibbo';n='Nacci' all have the same character count. +1 – Shelvacu Nov 10 '15 at 22:56 • You can save three bytes by using [b,f='Fibo',n='Nacci',f,b,f+n][~b%6], and two more by removing the parentheses in a=b+b=a. – primo Nov 14 '15 at 5:27 • Thank you @primo. That is a neat trick with the ~ operator. Never seen it before. And now I know why negative indexes are part of ruby:) – MegaTom Nov 16 '15 at 16:28 • Really need puts [ instead of puts[? – Erik the Outgolfer Jun 18 '16 at 21:52 • Roses are red, Violets are blue, for Haskell and Ruby, I have no clue. – Erik the Outgolfer Jun 21 '16 at 8:22 # ><>, 116 bytes 01:n1&61>. ao:@+:v vv?%2:< ">:3%?vv^16< o>:3%?!v~v<& bov"ci"< 6 ; io" n 6~? Focv1&< o= "o">+:aa*!o^ >^>"aN"ooo^  Try it online! • Welcome to the site! :) – DJMcMayhem Feb 12 '18 at 20:54 • You could probably combine both the 3% sections – Jo King Feb 13 '18 at 2:22 • @JoKing You'd think so, but they actually lead to different outcomes if n%3!=0. I'm sure there is a way to combine them, but it would mean restructuring the entire program, and I imagine it would actually be longer. – hakr14 Feb 13 '18 at 2:40 # Pyth, 39 Vtu+Gs>2G99U2|+*!%N2"Fibo"*!%N3"Nacci"N  Very similar to the standard fizzbuzz solution, just with a generator for the Fibonacci numbers. Try it here ## C#, 498392 320 bytes I just really wanted to do this with linq, too bad I had to write my own sum function for BigInteger that really killed it :-( using System.Linq;using System.Numerics;using System.Collections.Generic;static class a{static void Main(){var f=new List<BigInteger>(){1,1};while(f.Count<100)f.Add(f.Skip(f.Count-2).Take(2).Aggregate((a,b)=>b+a));f.ForEach(x=>{System.Console.WriteLine(x%6==0?"FiboNacci":x%2==0?"Fibo":x%3==0?"Nacci":x.ToString());});}}  Ungolfed: using System.Linq; using System.Numerics; using System.Collections.Generic; static class a { static void Main() { var f=new List<BigInteger>(){1,1}; while(f.Count<100) f.Add(f.Skip(f.Count-2).Take(2).Aggregate((a,b)=>b+a)); f.ForEach(x=> { System.Console.WriteLine(x%6==0?"FiboNacci":x%2==0?"Fibo":x%3==0?"Nacci":x.ToString()); }); } }  Edit: Down to 320 bytes thanks to LegionMammal978 for the aggregate suggestion and thanks to olegz's C# answer for the x%6 shorthand for X%2 && x%3 as well as the use of ternary operators in a single WriteLine statement. • Have you heard of the Aggregate LINQ function? – LegionMammal978 Nov 9 '15 at 22:55 • Replace "sum" with "t" to shave 6 bytes. – Xantix Nov 10 '15 at 1:42 # Python 2, 171 121 bytes "Brute force approach." a=[1,1] print 1 for _ in"q"*99:print[a[1],"Fibo","Nacci","FiboNacci"][a.append(a.pop(0)+a[0])or(1-a[0]%2)+(a[0]%3<1)*2]  ## Javascript, 93 90 86 Bytes for(a=0,b=1,i=100;i--;a=[b,b=a+b][0])console.log((b%2?'':'Fibo')+(b%3?'':'Nacci')||b)  • You could save four bytes by changing a=[b,b=a+b][0] to b=a+b,a=b-a. Also, in a completely unrelated note, I like the way you answer like really fast in Stack Overflow hehe Have a nice day – Piyin Nov 2 '17 at 22:22 ## Python 2, 100 bytes x=[1,1] exec"x+=[x[-1]+x[-2]];"*98 print"\n".join(["Fibo"*(i%2==0)+"Nacci"*(i%3==0)orifor i in x])  For the large numbers, adds a L to the end showing it's a long number. If that's a problem, here is a 104 byte solution x=[1,1] exec"x+=[x[-1]+x[-2]];"*98 print"\n".join(["Fibo"*(i%2==0)+"Nacci"*(i%3==0)or str(i)for i in x])  • You can shorten the for loop using this tip: codegolf.stackexchange.com/a/5047/42736. In particular the exec tip looks good. – J Atkin Nov 9 '15 at 19:19 • +1 for the exec <program_string>*n trick. Nice! – agtoever Nov 10 '15 at 9:01 # Javascript(ES6), 137 134 bytes g=x=>(a=[1,1],f=(x)=>(a[x]=y=a[x-1]+a[x-2],(y%2&&y%3?y:(!(y%2)?'Fibo':'')+(!(y%3)?'Nacci':''))+'\n'+((++x<99)?f(x):'')),'1\n1\n'+f(2))  Recursive function that calculates fibonnacci, put it in an array then output Fibo,Nacci or the number and call itself to calculate next until 100. It breaks at 73 because of javascript Number precision. Only way to get around that would be to add my own bit calculation. • This doesn't work, it goes wrong after 5527939700884757 + 8944394323791464 = 14472334024676220 when it should be 14472334024676221 because JavaScript uses 16 bit precision floats and that requires 17 bits of precision. You should also print 1 twice. – George Reith Nov 10 '15 at 17:31 • Added the print 1 twice. For the precision, I need to change everythin on the code to make it work (not using Number but Uint32Array and doing computation bits by bits) – Naouak Nov 10 '15 at 22:18 ## QBasic, 144 141 bytes Not particularly small, but it beats C++ and C# r=1:FOR i=1 TO 046:a$="":q=p+r
IF q MOD 2=0 THEN a$="Fibo" IF q MOD 3=0 THEN a$=a$+"Nacci" IF a$="" THEN a$=STR$(q)
PRINT a$:r=p:p=q:NEXT  No declarations, used the : wherever possible because it's 1 byte cheaper than CRLF. Prefixed a 0 to the loop counter: Basic will overflow on the 47th Fibonacci character, so compensated for the extra byte that should be there. EDIT: Neil saved me 3 bytes: 141 bytes. • You can remove the first a$+ since it's known to be the empty string at this point. – Neil Nov 11 '15 at 8:40

## Wolfram Language, 84 bytes

Kind of cheating of course, because of the built in Fibonacci.

t=Fibonacci@Range@100;g=(t[[#;;;;#]]=#2)&;g[3,Fibo]g[4,Nacci]g[12,FiboNacci]Print/@t


Example command to run the script

/Applications/Mathematica.app/Contents/MacOS/WolframKernel -script ~/Desktop/fibo.wl


# Perl, 74 bytes

map{print+(Fibo)[$_%2].(Nacci)[$_%3]||$_ for$a+=$b||1,$b+=$a}1..50  Requires the following command line option: -lMbigint, counted as 8. Sample Usage $ perl -lMbigint fibo-nacci.pl


Perl, 79 bytes

use bigint;map{print+(Fibo)[$_%2].(Nacci)[$_%3]||$_,$/for$a+=$b||1,$b+=$a}1..50


Same as above, without requiring any command line options.

# GolfScript, 47 bytes

100,{1.@{.@+}*;..2%!'Fibo'*\3%!'Nacci'*+\or}%n*


Explanation

100,            # push 0..99
{               # map
1.@           # push 1 twice, rotate counting var to the top
{             # apply that many times
.@+         # copy the top, rotate and add
# if the stack is [a b], this produces: [a b b] -> [b b a] -> [b b+a]
}*
;..           # discard the top, duplicate twice
2%!'Fibo'*\   # divisible by 2 ? 'Fibo' : ''
3%!'Nacci'*   # divisible by 3 ? 'Nacci' : ''
+\or          # concatenate, if empty use the numeric value instead
}%
n*              # join all with a newline


# PARI/GP, 76 73 bytes

Saved three bytes courtesy of Mitch Schwartz.

for(n=b=!a=1,99,b=a+a=b;print(if(b%2,"",Fibo)if(b%3,if(b%2,b,""),Nacci)))


Sample Usage

$gp -qf < fibo-nacci.gp  • It's shorter not to use built-in; I got 73 with for(i=b=!a=1,99,b=a+a=b; ... – Mitch Schwartz Nov 14 '15 at 18:39 • @MitchSchwartz it used to be called fibo ;) – primo Nov 14 '15 at 23:12 # ><>, 128 119 bytes 111&v >:3%0=?v> v ?;ao>:2%0=?v :3%0=?v :n>:}+&:1+&aa*= ^oooo < ^ooooo < >"obiF"^>"iccaN"^  I shamelessly stole borrowed an existing program FizzBuzz program and modified it to work for the Fibo Nacci sequence. It outputs numbers forever. Now it is fixed, i.e. it only outputs 100 numbers. Try it here. • You must only output the first 100 Fibo Nacci numbers, no more, no less. – Kritixi Lithos Nov 11 '15 at 5:31 • @ΚριτικσιΛίθος I finally got around to making it only output 100 numbers. – DanTheMan Nov 18 '15 at 16:52 • This outputs 101 numbers on TIO but doesn't work at the linked site – Jo King Feb 13 '18 at 4:10 # Pyth, 51 bytes V.Wn100lHaZ+@Z_1@Z_2[1 1)|+*"Fibo"}2JPN*"Nacci"}3JN  Generates the Fibonacci sequence then decides what to print.  [1 1) - H = [1,1] Wn100lH - While len(H)!=100 aZ+@Z_1@Z_2 - H.append(H[-1]+H[-2]) V. - For N in H: JPN - Set J to the prime factorization of H *"Fibo"}2J - If there is a 2 in the factorization, add "Fibo" to a string *"Nacci"}3J - If there is a 3 in the factorization, add "Nacci" to a string + - Join them together | N - If the string isn't empty (If it isn't divisible by 2 or 3), print N - Else print the string  To test, try this (only does the first 20 numbers) V.Wn20lHaZ+@Z_1@Z_2[1 1)|+*"Fibo"}2JPN*"Nacci"}3JN  • How long does it take to run the actual program? – Kritixi Lithos Nov 9 '15 at 17:45 • I have no idea, it didn't in the 30 seconds it took to work out that working out such large prime factorizations would probably slow it down a lot. – Blue Nov 9 '15 at 17:46 # Clojure, 127 bytes (def f(lazy-cat[1 1](map +' f(rest f))))(doseq[x(take 100 f)](println(str(if(even? x)'Fibo)({0'Nacci}(mod x 3)(if(odd? x)x)))))  Ungolfed: (def fib (lazy-cat [1 1] (map +' fib (rest fib)))) (doseq [x (take 100 fib)] (println (str (if (even? x) 'Fibo) ({0 'Nacci} (mod x 3) (if (odd? x) x)))))  Some tricks used: • That pretty little def that gives the Fibonacci sequence itself is stolen shamelessly from Konrad Garus. • str can take symbols as input. Crazy, right? • Maps and default values are the shortest way to write if in some cases. • What is lazy-cat? – Kritixi Lithos Nov 10 '15 at 5:02 • @ΚριτικσιΛίθος It lazily concatenates multiple sequences. In this case, it concatenates the first two elements of the Fibonacci sequence ([1 1]) with the result of summing each element in the Fibonacci sequence with the element following it. – Sam Estep Nov 10 '15 at 11:54 • Am I right in guessing that this is basically the Clojure version of fibs = 0 : 1 : zipWith (+) fibs (tail fibs)? – Soham Chowdhury Nov 10 '15 at 13:09 • @SohamChowdhury Yes, as far as I can tell. – Sam Estep Nov 10 '15 at 13:14 # CJam, 44 bytes XX{_2$+}98*]{_B4bf%:!"Fibo Nacci"S/.*s\e|N}/


Try it online in the CJam interpreter.

## dc, 10089 79 bytes

[sG[]]sx[dn]s01df[sbdlb+lbrdd2%d[Fibo]r0!=xnr3%d[Nacci]r0!=xn*0!=0APzZ3>o]dsox


Inspired by http://c2.com/cgi/wiki?DeeCee

• Welcome to Programming Puzzles & Code Golf! – Dennis Nov 12 '15 at 18:05

## 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. – Kritixi Lithos Nov 13 '15 at 6:28

## F#, 202 163 149 bytes

Seq.unfold(fun(a,b)->printfn"%s"(a%6m|>function|0m->"FiboNacci"|2m|4m->"Fibo"|3m->"Nacci"|_->string a);Some(1,(b,a+b)))(1m,1m)|>Seq.take 100|>Seq.sum


This is an FSX (F# script) file

• I am surprised that this works – asibahi Aug 24 '16 at 19:35

# PHP, 75 bytes

<?for(;4e20>$b=bcadd($a,$a=$b)?:1;)echo[Fibo][++$i%3].[Nacci][$i%4]?:$b,~õ;  Surpisingly competitive. Requres PHP v5.5 or higher. I assume default settings, as they are without an .ini (you may disable your local .ini with the -n option). Sample Usage $ php -n fibo-nacci.php

• WIth -n bcadd doesn't work even when bcmath is installed. Without -n lots of stuff is output on stderr. – Sylwester Feb 12 '18 at 21:10
• Works on my box(es). – primo Feb 13 '18 at 8:35

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