Last active
          December 15, 2015 18:29 
        
      - 
      
- 
        Save meeDamian/5304112 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or 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
    
  
  
    
  | function f(n){var m=Math,s=m.sqrt(5),g=(1+s)/2,p=m.pow;return m.round((p(g,n)-p(1-g,n))/s);} // accurate version | |
| var m=Math,s=m.sqrt(5),g=(1+s)/2,p=m.pow,f=function(n){return m.round((p(g,n)-p(1-g,n))/s)}; // accurate w/pre-calculating | |
| function f(n){var m=Math,s=m.sqrt(5),g=(1+s)/2,p=m.pow;return((p(g,n)-p(1-g,n))/s);} // inaccurate version | |
| var m=Math,s=m.sqrt(5),g=(1+s)/2,p=m.pow,f=function(n){return((p(g,n)-p(1-g,n))/s)}; // inacurate w/pre-calculating | 
  
    
      This file contains hidden or 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
    
  
  
    
  | # Fibonacci efficient | |
| c=[0,1];f=(i)->[c[i] ?(->c[i]=f(i-1)+f i-2)(),0][+!i] | |
| c=[0,1];f=(i)->c[i] ?(->c[i]=f(i-1)+f i-2)() | |
| c=[0,1];f=(i)->c[i] ?(->c[i]=f(--i)+f --i)() | |
| # Factorial | |
| f=(i)->[(->i*f i-1),->1][+!i]() | 
  
    
      This file contains hidden or 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
    
  
  
    
  | // Factorial | |
| function f(i){return!i?1:f(i-1)*i} | |
| // Fibonacci short | |
| function b(i){return i<2?i:b(i-1)+b(i-2)} | |
| function b(i){return i<2?i:b(--i)+b(--i)} | |
| // Fibonacci efficient | |
| function a(i){return!i?0:(a.c[i]||(a.c[i]=a(i-1)+a(i-2)))}a.c=[,1] | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment