Created
July 21, 2018 18:32
-
-
Save vasa-develop/23023e60dd1f602c127ef867243b4ae5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// library contract - calculates fibonacci-like numbers; | |
contract FibonacciLib { | |
// initializing the standard fibonacci sequence; | |
uint public start; | |
uint public calculatedFibNumber; | |
// modify the zeroth number in the sequence | |
function setStart(uint _start) public { | |
start = _start; | |
} | |
function setFibonacci(uint n) public { | |
calculatedFibNumber = fibonacci(n); | |
} | |
function fibonacci(uint n) internal returns (uint) { | |
if (n == 0) return start; | |
else if (n == 1) return start + 1; | |
else return fibonacci(n - 1) + fibonacci(n - 2); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment