Daniel-Nikpayuk_SICP-Solutions/Chapter 1/1.2/exercise-1.11/exercise.lsp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Copyright 2015 Daniel Nikpayuk
;;
;; This file is part of SICP Solutions.
;;
;; SICP Solutions is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
;; as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
;;
;; SICP Solutions is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
;; of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License along with SICP Solutions. If not, see
;; <http://www.gnu.org/licenses/>.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;f(n) = n if n<3 and f(n) = f(n - 1) + 2f(n - 2) + 3f(n - 3) if n>=3:

(define (f-r n)
 (if (< n 3) n
  (+
   (f-r (- n 1))
   (* 2 (f-r (- n 2)))
   (* 3 (f-r (- n 3)))
  )
 )
)

(define (f-i n)
 (define (succ s1 s2 s3)
  (+ s1 (* 2 s2) (* 3 s3))
 )
 (define (rge f2 f1 f0 count)
  (if (= count 0)
   (succ f2 f1 f0)
   (rge (succ f2 f1 f0) f2 f1 (- count 1))
  )
 )
 (if (< n 3) n
  (rge 2 1 0 (- n 3))
 )
)

