> For the complete documentation index, see [llms.txt](https://gitbook.testingwaters.in/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.testingwaters.in/patterns/fibbonacci.md).

# Fibbonacci and Factorial

### Pisano Period

{% tabs %}
{% tab title="Patterns" %}
![Random colors based on Pisano Period](/files/-MSaUx0ZUiDF3z3Z7Nbd)
{% endtab %}

{% tab title="Colors 1" %}
![](/files/-MSkhEBxsEuZCd6FXFm0)
{% endtab %}

{% tab title="Colors 2" %}
![](/files/-MSkhPIqGo_NcKDvbku6)
{% endtab %}

{% tab title="Colors 3" %}
![](/files/-MSkhaMM4IB1B9Hqb8XV)
{% endtab %}

{% tab title="Colors 4" %}
![](/files/-MSkhjHs60lGHKYE2ZzW)
{% endtab %}

{% tab title="Colors 5" %}
![](/files/-MSkhpOY0OeBIYsd1ULa)
{% endtab %}
{% endtabs %}

![Pisano Period](/files/-MSaV2hySw_QIGTJ-kv3)

```d
wc = 20;
hc = 12;
wd = 2;
ht = 2;

//Pisano Period
fp1 = fibbonacci(1..wc)%(1..hc)<1>;

//Random Colors
uq1 = List.UniqueItems(List.Flatten(fp1,-1));
rn1 = Math.Round(Math.RemapRange(Math.RandomList(List.Count(uq1)),0,255));
cl1 = Color.ByARGB(255,rn1,List.Shuffle(rn1),List.Reverse(rn1));
cl2 = Dictionary.ByKeysValues(uq1+"",cl1).ValueAtKey(fp1+"");

//Panels
pn1 = Rectangle.ByWidthLength(Plane.ByOriginNormal(Point.ByCoordinates((wd/2..#wc..wd),0,(ht/2..#hc..ht)<2>),Vector.YAxis()),wd,ht).Patch();
pn2 = GeometryColor.ByGeometryColor(pn1,cl2);
```

{% file src="/files/-MSaVbBbGMlfUiP3JKgg" %}
Dynamo Version 2.11
{% endfile %}

### Fibbonacci Series

![Fibbonacci](/files/-MQLY7QturpAupQ5P1Wm)

```d
def fibbonacci(n)
{
    return [Imperative]
    {
	    if (n == 0)
	    {
	    	return 0;
	    }
	    elseif (n == 1)
	    {
	    	return 1;
	    }
	    else
	    {
	    	return (fibbonacci(n-1) + fibbonacci(n-2));
	    }
	}
};
```

### Factorials

![Factorial](/files/-MQLY4BZ8w89dH66C9hH)

```d
def factorial(n)
{
    return [Imperative]
    {
	    if (n <= 1)
	    {
	    	return 1;
	    }
	    else
	    {
	    	return n * factorial(n-1);
	    }
	}
};
```
