Created
          October 19, 2008 18:04 
        
      - 
      
- 
        Save luislavena/17894 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
    
  
  
    
  | def fib(n) | |
| if n <= 1 | |
| return n | |
| else | |
| return fib(n-1) + fib(n-2) | |
| end | |
| end | |
| puts fib(30) | 
  
    
      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
    
  
  
    
  | s(:block, | |
| s(:defn, | |
| :fib, | |
| s(:scope, | |
| s(:block, | |
| s(:args, :n), | |
| s(:if, | |
| s(:call, s(:lvar, :n), :<=, s(:array, s(:lit, 1))), | |
| s(:return, s(:lvar, :n)), | |
| s(:return, | |
| s(:call, | |
| s(:fcall, | |
| :fib, | |
| s(:array, s(:call, s(:lvar, :n), :-, s(:array, s(:lit, 1))))), | |
| :+, | |
| s(:array, | |
| s(:fcall, | |
| :fib, | |
| s(:array, s(:call, s(:lvar, :n), :-, s(:array, s(:lit, 2)))))))))))), | |
| s(:fcall, :puts, s(:array, s(:fcall, :fib, s(:array, s(:lit, 30)))))) | 
  
    
      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
    
  
  
    
  | fib = function(n) { | |
| if (n <= 1) { | |
| return n | |
| } | |
| else { | |
| return (fib((n - 1)) + fib((n - 2))) | |
| } | |
| } | |
| $print(fib(30)) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment